ConfigParser is a Python module for reading and writing configuration files that have a structure similar to those of INI files in Microsoft Windows.
Questions tagged [configparser]
683 questions
4
votes
2 answers
Python ConfigParser use defaults if not in configuration file
What's the best way to use a default value if it isn't defined in a configuration file? E.g. in the example below, perhaps only listen_address is defined in the configuration, and listen_port is absent.
I'm trying something like this:
import…

Rusty Lemur
- 1,697
- 1
- 21
- 54
4
votes
1 answer
python 3 configparser.read() does not raise an exception when given a non-existing file
When I attempt to read a non-existing file using configparser.read, I think it ought to raise an exception. It doesn't. It returns an empty list instead. Obviously, I can test for an empty list and raise an exception. It just seems to me to be…

Jeff Silverman
- 692
- 1
- 8
- 15
4
votes
2 answers
Python Config Parser environment variables
I am trying to read some environment variables into my ConfigParser file.
I was referring to this answer but I am getting
"InterpolationDepthError: Value interpolation too deeply recursive" error.
section: [amazon]
option : amazon_access_key
…

Ankita Gupta
- 155
- 2
- 14
4
votes
1 answer
python config parser cache to reduce I/O on an embedded system
In my project we use a config file that's parsed with the configparser module. Is there any way to cache the entire config file, and then use configparser methods to read it from memory? I'm hoping to not have to just store the config variables in a…

Falmarri
- 47,727
- 41
- 151
- 191
4
votes
1 answer
Python 3 ConfigParser reading the inline comments as well
I have the following code, where the filePath is the path to a cfg file on disk. When I parse it, it also reads the inline comments (the ones with space + ";").
Some lines of the result:
xlsx:Yes ;…

Alexandru Antochi
- 1,295
- 3
- 18
- 42
4
votes
3 answers
Get a list from config.ini file
In my config file I have something like that :
[Section_1]
List=Column1,Column2,Column3,Column4
Now, I would like to process it in my main file as normal lists :
config = configparser.ConfigParser()
config.read("configTab.ini")
for…

bazyl
- 263
- 1
- 7
- 17
4
votes
1 answer
Can logging and CherryPy share the same config file?
Both the Python logging module and CherryPy's Config API use ConfigParser files. Therefore, I assumed that I could use one single config file for my own applications configuration, it's logging configuration, and CherryPy's configuration.
When my…

Eli Courtwright
- 186,300
- 67
- 213
- 256
4
votes
1 answer
Using a config file to specify operations to execute in Python
I'm trying to build dynamic operations using a config file, python and ConfigParser. I'm fairly new to Python (2 weeks old) so I'm not sure if this is even possible, which is why I thought I'd ask.
Here's a sample config file:
[General]
Volume File…

friendlycat
- 43
- 5
4
votes
1 answer
Reading configfiles with no key but value entries using python configparser
I have a question regarding to the python configparser module. I'm using Python 3.x.
I have a lot of .ini-files which are corrupt, respectively in my oppinion defect. e.g. there are values without regarding key…

Ben
- 43
- 3
4
votes
2 answers
Argparse - configparser.Interpolation missing option error
I am using Argparse for fetching the necessary value from config file.
For example:
python arg.py --event_conf=/opt/open-stack-tools/track_events.conf --openstack_conf=/etc/nova/nova.conf
I need to fetch value from two different files.
I can be…

Murali
- 1,084
- 1
- 11
- 28
4
votes
2 answers
Stop ConfigParser adding spaces to delims after upgrade from python 2.7.3 to 2.7.9
After being forced to use a later version of python, ConfigParser now insists on adding spaces to each side of any delims when modifying a configuration file.
e.g.
setting=90 becomes: setting = 90
This was not the behavior in the earlier version,…

Chris Atkinson
- 75
- 1
- 7
4
votes
2 answers
socket.gaierror: [Errno 8] nodename nor servname provided, or not known
I'm trying to connect to my ftp server with the following Python script on a Mac running OS X Yosemite (10.10.5):
from ftplib import FTP
import ConfigParser
config_file = "ftp.config"
config = ConfigParser.ConfigParser()
try:
…

St4rb0y
- 317
- 3
- 5
- 22
4
votes
1 answer
Where is a good place/way to store Windows config files for Python scripts?
I have a script/program I am working on that requires a configuration file (I am using ConfigParser). On linux, I will default to store these variables in ~/.myscript using the os.getenv('HOME') function.
With Windows, I know I can use…

thornomad
- 6,707
- 10
- 53
- 78
4
votes
1 answer
Python configparser: Copy comments from input file
I'm using configparser and Python 3.3 to create a script which makes some small modifications to config files. These config files often contain commented-out lines, like so:
[Section]
Value1=Foo
;Very important comment
;Another very important…

John Allie
- 245
- 2
- 10
4
votes
3 answers
Configparser set with no section
Is there a way for configparser in python to set a value without having sections in the config file?
If not please tell me of any alternatives.
Thank you.
more info:
So basically I have a config file with format:
Name: value
It's a system file that…

Cobra Kai Dojo
- 1,018
- 2
- 12
- 25