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
3
votes
1 answer

Duplicate section when adding a new option configparser

When I add a new option to a section and write the file to config it always seems to duplicate the section and adds the new one with the new option. Ideally I'd like to avoid this and only have one section, how do I achieve this? Example…
chomes
  • 59
  • 7
3
votes
3 answers

ConfigParser.MissingSectionHeaderError: File contains no section headers

I am trying to fetch data from a .cfg (configuration file) in python but I am always getting the error ConfigParser.MissingSectionHeaderError: File contains no section headers. The screenshot of the problem Here is the link for the .cfg…
joginder singh
  • 41
  • 1
  • 1
  • 7
3
votes
0 answers

python configparser alias for sections in ini files

In my *.ini files I have sections like these: [server-a] applicationkey = xuserid = host = : [server-b] applicationkey = xuserid = host = : How can I add section…
MortenB
  • 2,749
  • 1
  • 31
  • 35
3
votes
2 answers

Config parsing Robotframework

I have a project that has been implemented using a mix of python and Robotframework scripts. I have have a bunch of configuration items stored inside my projects Config.ini file which looks like this: [Environment] Username:…
Souparno
  • 350
  • 1
  • 5
  • 18
3
votes
3 answers

How to evaluate simple math expressions in config files

I would like to use a configuration file with some simple math expressions like adding or substracting. For example: [section] a = 10 b = 15 c = a-5 d = b+c Is there any way to do this using a ConfigParser module? I found some examples of using…
KozaK
  • 31
  • 1
  • 3
3
votes
5 answers

MissingSectionHeaderError: File contains no section headers.(configparser)

I'm using configparser in order to read and modify automatically a file conf named 'streamer.conf'. I'm doing this : import configparser config = configparser.ConfigParser() config.read('C:/Users/../Desktop/streamer.conf') And then it breaks…
3
votes
2 answers

Python Json Config 'Extended Interpolation'

I am currently using the Python library configparser: from configparser import ConfigParser, ExtendedInterpolation I find the ExtendedInterpolation very useful because it avoids the risk of having to reenter constants in multiple places. I now have…
user2579685
  • 319
  • 9
  • 19
3
votes
1 answer

ValueError in ConfigParser in python3

I am trying to update my configuration.ini file's, [Financial Times: Financial-Services] section's last_entry_id with the following string:…
psr
  • 2,619
  • 4
  • 32
  • 57
3
votes
0 answers

ConfigParser returning values in a list instead of a string

I have a script that is reading an ini file. When I initially wrote the script I was using a default ini. ConfigParser returned the values of the keys in a list. EG config.get('Section', 'Key') would return ['value']. I simply tacked on a slice…
Greyed
  • 31
  • 3
3
votes
4 answers

ConfigParser - print config.sections() returns []

I'm trying to use a ConfigParser module to parse an *.ini file. The problem is that when I try to print sections or whatever, it returns empty list…
Milano
  • 18,048
  • 37
  • 153
  • 353
3
votes
1 answer

How to insert multi-line value using configparser

I have to modify a config file which has similar structure to an .ini file. But the problem is that config file has multiple lines for single value. How to modify it? For example here is the configuration I want to modify. [INCLUDES] # Read common…
r_yu
  • 41
  • 1
  • 7
3
votes
2 answers

configparser not working in Python 3.4, NoSectionError but works fine in PyCharm

I worked on a Python 3.4 script in PyCharm 4.5. (repo: https://github.com/Djidiouf/bbot ) In it, I used import configparser without any problem for retrieving some values in a config.cfg: config =…
Djidiouf
  • 786
  • 1
  • 10
  • 23
3
votes
4 answers

Python ConfigParser KeyError:

I am following an example to read a config file from the following: https://wiki.python.org/moin/ConfigParserExamples But I get a KeyError and can't figure out why. It is reading the files and I can even print the sections. I think I am doing…
whoopididoo
  • 411
  • 2
  • 10
  • 19
3
votes
1 answer

configparser: parsing error with omitted values

I'm using Python's old-fashioned configparser module to read config-files from the filesystem. To check whether a user-provided config-file uses correct 'syntax' I compare all section keys and subkeys to a reference config-file ref_config.ini…
albert
  • 8,027
  • 10
  • 48
  • 84
3
votes
0 answers

ConfigParser with multiple sections and same option names?

I would like to get ConfigParser working for what seems to be a simple problem but I have an ancient 2.2 Jython system (that cannot be updated). I would like to loop through the sections in my config file and use the same operation on its values.…
user3723061
  • 31
  • 1
  • 3