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

How do I get the location of the entry module in python?

I know I can use __file__ and os.path.* to figure out the path of the current module. What about the entry module? I'm trying to load an ini file into ConfigParser from a module based on the hostname, but I want it to be relative to the entry…
Justin Dearing
  • 14,270
  • 22
  • 88
  • 161
3
votes
1 answer

Python 2, ConfigParser: retrieving the line number of a section/option

Is there a way in the Package "ConfigParser" to obtain the line-number in which the Parser had read a specific section or key? INI-File [section1] option1=3 option2=4 [section2] option3=right i.e. a method that returns the line-number…
meister_reineke
  • 364
  • 1
  • 14
3
votes
3 answers

How to read config(.ini) file in python which will work on 2.7 and 3.x python

Should I use ConfigParser which is compatible with python 2.7 and 3.x or do you suggest any other module in python which is compatible with both versions of python for reading config file?
3
votes
3 answers

Python Config Parser can't find section?

I'm trying to use ConfigParser to read a .cfg file for my pygame game. I can't get it to function for some reason. The code looks like this: import ConfigParser def main(): config = ConfigParser.ConfigParser() config.read('options.cfg') …
user3033405
  • 83
  • 1
  • 1
  • 4
3
votes
1 answer

Use of external modules in a logging configuration file

I have setup the following configuration file for the logging module in python2.7 with…
Mike
  • 6,813
  • 4
  • 29
  • 50
3
votes
1 answer

Use variables in another section in Python ConfigParser

I know I can use %(values)s to use the exist variable in the config file. But it seems that I can only use the variable in the same section. Is there any way to use the variable in other sections?
Alfred
  • 165
  • 1
  • 1
  • 8
3
votes
2 answers

How To Read and Write to a INI file in Python

How to edit an INI file in Python 2.7 I am trying to edit an INI config file that already has the Sections and Options I need. However I need to update the values depending on a checkboxlist in wxPython. Currently everything is working :), but I…
3
votes
3 answers

Python ConfigParser: how to work out options set in a specific section (rather than defaults)

I have a config file that I read using the RawConfigParser in the standard ConfigParser library. My config file has a [DEFAULT] section followed by a [specific] section. When I loop through the options in the [specific] section, it includes the ones…
user265454
  • 3,071
  • 3
  • 21
  • 12
3
votes
1 answer

python dictionary from config parser if value and "%(" in value: argument of type 'int' is not iterable

Getting this error in as random, sometimes appear, sometimes not: for i in range(1,32): sezione = "GRP"+str(i) dizionarioGRP = dict(config.items(sezione)) print int(dizionarioGRP['r']) and this is the error File…
user2239318
  • 2,578
  • 7
  • 28
  • 50
3
votes
1 answer

config parser: Choosing name and value delimiter

Let's say I have one test.ini file with the following lines: [A] name1 [0,1]=0 name2 a:b:c / A:B:C [0,1]=1 When I parse it like this: A = ConfigParser.ConfigParser() with codecs.open('test.ini', 'r') as f: A.optionxform = str …
Krcevina
  • 131
  • 4
  • 13
3
votes
2 answers

How can I remove the white characters from configuration file?

I would like to modify the samba configuration file using python. This is my code from ConfigParser import SafeConfigParser parser = SafeConfigParser() parser.read( '/etc/samba/smb.conf' ) for section in parser.sections(): print section for…
Mokus
  • 10,174
  • 18
  • 80
  • 122
2
votes
6 answers

Is something like ConfigParser appropriate for saving state (key, value) between runs?

I want to save a set of key, value pairs (string, int) between runs of a Python program, reload them on subsequent runs and write the changes to be available on the next run. I don't think of this data as a configuration file, but it would fit the…
Dennis Williamson
  • 346,391
  • 90
  • 374
  • 439
2
votes
2 answers

Parsing a hierarchical config file structure with Python

I'm using ConfigParser for a project with a configuration file that is getting to large. I plan to split it but maintain a central config file that points to the others. I haven't seen this in the documentation, but can ConfigParser handle a…
Jonathan Livni
  • 101,334
  • 104
  • 266
  • 359
2
votes
2 answers

Python 2.x - ConfigParser stripping blank lines in multiline value

The following is the file parsed by ConfigParser: [Ticket] description = This is a multiline string. 1 2 4 5 7 As described by the official Python wiki for ConfigParser examples, here is the helper function: def ConfigSectionMap(section): …
paragbaxi
  • 3,965
  • 8
  • 44
  • 58
2
votes
1 answer

How to use '#' character in INI file?

I am having a trouble with connecting MSSQL to python using Configparser, and one of DB's password has included a character '#'. Since we don't use escape character " in INI file, then how should I use a character #? (byw, I can't change the…
jhseo
  • 25
  • 3