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
2
votes
0 answers
Can't read configparser from vscode, while readable on command-line .py code
A simple code to read a config file with ConfigParser works fine when it's run on command-line, but the same .py code cannot read the same config file when using VS code.
I've changed the default venv for VScode to make sure to use the same…

pomme
- 97
- 1
- 3
- 11
2
votes
1 answer
In ConfigParser how to get only section-local options?
Consider the following MWE named foo.py:
#!/usr/bin/env python3
from configparser import ConfigParser
if __name__ == "__main__":
cfg = ConfigParser()
with open("foo.ini") as ini:
cfg.read_file(ini)
for section in…

0xC0000022L
- 20,597
- 9
- 86
- 152
2
votes
1 answer
How to store and retrieve a dictionary of tuples in config parser python?
I'm using the configparser library in python to manage my configuration files.
But, I can't find a method to store and retrieve tuples data-structure through it.
My data is a dictionary of tuples.
name_mapper = {
0 = (0, 0)
1 = (0, 1)
2…

Rohit Lal
- 2,791
- 1
- 20
- 36
2
votes
5 answers
Python - ConfigParser throwing comments
Based on ConfigParser module how can I filter out and throw every comments from an ini file?
import ConfigParser
config = ConfigParser.ConfigParser()
config.read("sample.cfg")
for section in config.sections():
print section
for option in…
Davey
2
votes
0 answers
Using python configparser to update .ini file section value but cant figure how to update the correct value as directed
I have been tasked with creating a program that will update a value in an ini file. The ini file looks like;
[link1]
name = nodeB
ip = 127.0.0.1
port = 1002
cost = 190
[link2]
name = nodeC
ip = 127.0.0.1
port = 1003
cost = 210
The command…

Wayzival
- 23
- 3
2
votes
1 answer
Python3 configparser startswith first arg must be bytes or a tuple of bytes, not str
I am doing this:
tar = tarfile.open("stuff.tar")
cfg = configparser.ConfigParser(allow_no_value=True)
cfg.read_file(tar.extractfile("ook.ini"))
The file "ook.ini" is indeed inside the "stuff.tar" archive.
However, I get this:
[…] ← Really not…

Sardathrion - against SE abuse
- 17,269
- 27
- 101
- 156
2
votes
0 answers
edit a file with nameless section with ConfigParse
I am tryng to edit a Splunk config file that has a section with no name
Conf file
# Application-level permissions
[]
access = read : [ * ], write : [ admin, power ]
Code
>>> import configparser
>>> config = configparser.RawConfigParser()
>>>…

rmacian
- 21
- 2
2
votes
1 answer
Python ConfigParser - raise KeyError (key)
config.ini
[datasource]
host = localhost
config.py
import configparser
import os
config = configparser.ConfigParser()
config.read(os.path.join(os.getcwd(), 'config.ini'))
host = config['datasource']['host']
Test.py
import…

Jack Lim
- 195
- 2
- 5
- 16
2
votes
0 answers
How to read config file with multiple keys with python3 configparser?
I have a config file that has multiple keys with the same name.
[parentnode]
parentname = Name of parent
child = Name of first child
child = Name of second child
child = Name of third child
child = Name of fourth child
I need to…

softwarematter
- 28,015
- 64
- 169
- 263
2
votes
1 answer
Usage of ConfigParser.setdefault()
I am trying to set default values on an instance of configparser.ConfigParser after its instantiation.
While inspecting the instance I found the method ConfigParser.setdefault():
Help on method setdefault in module collections.abc:
setdefault(key,…

Richard Neumann
- 2,986
- 2
- 25
- 50
2
votes
1 answer
Python - KeyError(key) is raised but it shouldn't
Why this code raises error:
import configparser
import os
path = '/home/solus/Downloads/TestOnMe'
os.chdir(path)
config = configparser.ConfigParser()
config.read('extensions.ini')
extensions = config['Extensions']
But on contrary this code…

Martin Corelli
- 23
- 1
- 8
2
votes
1 answer
Python get diff for ConfigParser
Let say I have old and new configurations initialized
from ConfigParser import ConfigParser
old_config = ConfigParser()
old_config.read(config_file1)
new_config = ConfigParser()
new_config.read(config_file2)
How can I get the difference between…

David Mnatsakanyan
- 455
- 1
- 4
- 15
2
votes
3 answers
How to add section and values to ini using configparser in Python?
I would like to ask why the ini file created using my code is empty.
I intend to create an ini file on the same directory as that of the py file.
So far, the ini is generated but it is empty.
import os
import configparser
config =…

wildfire
- 119
- 2
- 4
- 9
2
votes
1 answer
Pyspark - Python3 get variable from file using configparser
I am trying to get a variable from a file using Configparser but it always returns a string instead of a variable. Please assist
config.ini
[db]
connection_sting =sqlContext.read.format(driver).load(table_nm)
config_conn = ConfigParser()…

Jack
- 957
- 3
- 10
- 23
2
votes
1 answer
How to read a newline from config file using Python ConfigParser
I have a config File "Email_Properties.cfg" as below
[email_Properties]
Subject=Security keywords Scan Info
Body=securityDetails\n Note : This is an auto generated mail
I am using ConfigParser to read file and print the content, Not able to get…

Sunil Kumar
- 367
- 2
- 5
- 19