Questions tagged [configparser]

ConfigParser is a Python module for reading and writing configuration files that have a structure similar to those of INI files in Microsoft Windows.

683 questions
29
votes
3 answers

How to read config from string or list?

Is it possible to read the configuration for ConfigParser from a string or list? Without any kind of temporary file on a filesystem OR Is there any similar solution for this?
Lucas
  • 3,376
  • 6
  • 31
  • 46
27
votes
9 answers

ConfigParser and String interpolation with env variable

it's a little bit I'm out of python syntax and I have a problem in reading a .ini file with interpolated values. this is my ini file: [DEFAULT] home=$HOME test_home=$home [test] test_1=$test_home/foo.csv test_2=$test_home/bar.csv Those lines from…
nkint
  • 11,513
  • 31
  • 103
  • 174
27
votes
5 answers

ConfigParser with Unicode items

my troubles with ConfigParser continue. It seems it doesn't support Unicode very well. The config file is indeed saved as UTF-8, but when ConfigParser reads it it seems to be encoded into something else. I assumed it was latin-1 and I thougt…
pojo
  • 5,892
  • 9
  • 35
  • 47
26
votes
4 answers

How can I set default values for SafeConfigParser?

I have a config file as follows: [job] mailto=bob logFile=blahDeBlah.txt I want to read the options using SafeConfigParser: values = {} config = ConfigParser.SafeConfigParser() try: config.read(configFile) jobSection = 'job' …
Martlark
  • 14,208
  • 13
  • 83
  • 99
26
votes
5 answers

Update INI file without removing comments

Consider the following INI file: [TestSettings] # First comment goes here environment = test [Browser] # Second comment goes here browser = chrome chromedriver = default ... I'm using Python 2.7 to update the ini file: config =…
sarbo
  • 1,661
  • 6
  • 21
  • 26
23
votes
2 answers

Python 2.4.3: ConfigParser.NoSectionError: No section: 'formatters'

Trying to use a logging configuration file to implement TimedRotatinigFileHandler. Just won't take the config file for some reason. Any suggestions appreciated. x.py: import logging import logging.config import…
user981163
  • 231
  • 1
  • 2
  • 5
23
votes
4 answers

Change value in ini file using ConfigParser Python

So, I have this settings.ini : [SETTINGS] value = 1 And this python script from ConfigParser import SafeConfigParser parser = SafeConfigParser() parser.read('settings.ini') print parser.get('SETTINGS', 'value') As you can see, I want to read…
CarefullyAdvanced
  • 437
  • 1
  • 4
  • 15
23
votes
8 answers

Python ConfigParser - values between quotes

When using ConfigParser module I would like to use values containing of multiple words set in cfg file. In this case seems trivial for me to surround the string with quotes like (example.cfg): [GENERAL] onekey = "value in some words" My problem is…
Davey
22
votes
3 answers

ConfigParser VS SafeConfigParser in python 2.7

What are the differences between ConfigParser and SafeConfigParser? And why, exactly, is the latter is safer? What's 'unsafe' about ConfigParser? I know that SafeConfigParser inherited the ConfigParser, what did it do different?
Ticks
  • 528
  • 1
  • 5
  • 11
22
votes
3 answers

What's better, ConfigObj or ConfigParser?

Which is better for creating a settings file for Python programs, the built-in module (ConfigParser), or the independent project (ConfigObj)?
Apocryphon
  • 221
  • 1
  • 2
  • 3
21
votes
2 answers

Python configparser will not accept keys without values

So I'm writing a script that reads from a config file, and I want to use it exactly how configparser is designed to be used as outlined here: http://docs.python.org/release/3.2.1/library/configparser.html I am using Python 3.2.1. The script, when…
Sparc
  • 287
  • 1
  • 3
  • 7
21
votes
5 answers

How to ConfigParse a file keeping multiple values for identical keys?

I need to be able to use the ConfigParser to read multiple values for the same key. Example config file: [test] foo = value1 foo = value2 xxx = yyy With the 'standard' use of ConfigParser there will be one key foo with the value value2. But I need…
Alex
  • 41,580
  • 88
  • 260
  • 469
20
votes
2 answers

Mocking Method Calls In Python

I have been searching stack exchange and around the web for how to do this, but I cannot understand how to mock behaviors for methods. I am trying to mock openpyxl behaviors and behaviors for my custom class. Here is my attempt: import unittest from…
EliSquared
  • 1,409
  • 5
  • 20
  • 44
19
votes
5 answers

How to exclude DEFAULTs from Python ConfigParser .items()?

I'm using ConfigParser to load in data from a configuration file as follows: test.conf: [myfiles] fileone: %(datadir)s/somefile.foo filetwo: %(datadir)s/nudderfile.foo load.py: import ConfigParser config = ConfigParser.ConfigParser({'datadir':…
user264902
  • 201
  • 1
  • 2
  • 5
17
votes
4 answers

Python ConfigParser interpolation from foreign section

With Python ConfigParser, is it possible to use interpolation across foreign sections? My mind seems to tell me I've seen that it's possible somewhere, but I can't find it when searching. This example doesn't work, but it's to give an idea of what…
user16738
  • 1,223
  • 8
  • 10
1
2
3
45 46