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
7
votes
2 answers

How to remove a section from an ini file using Python ConfigParser?

I am attempting to remove a [section] from an ini file using Python's ConfigParser library. >>> import os >>> import ConfigParser >>> os.system("cat a.ini") [a] b = c 0 >>> p = ConfigParser.SafeConfigParser() >>> s = open('a.ini', 'r+') >>>…
ultimoo
  • 495
  • 2
  • 5
  • 13
7
votes
2 answers

Adding and reading a config.ini file inside python package

I am writing my first python package which I want to upload on PyPI. I structured my code based on this blog post. I want to store user setting in a config.ini file. Read it once(every time the package is run) in separate python module in same…
Abhimanyu Pathania
  • 335
  • 2
  • 7
  • 18
7
votes
4 answers

Gettings settings and config from INI file for Pyramid functional testing

In a real Pyramid app it does not work per docs http://docs.pylonsproject.org/projects/pyramid//en/latest/narr/testing.html : class FunctionalTests(unittest.TestCase): def setUp(self): from myapp import main app =…
LetMeSOThat4U
  • 6,470
  • 10
  • 53
  • 93
7
votes
5 answers

Export with alphabetical sort in Python ConfigParser

Is there any solution to force the RawConfigParser.write() method to export the config file with an alphabetical sort? Even if the original/loaded config file is sorted, the module mixes the section and the options into the sections arbitrarily, and…
Htechno
  • 5,901
  • 4
  • 27
  • 37
7
votes
1 answer

Python Write Dictionary Contents to ConfigParser

I am trying to write (and later read into) the contents of a dictionary to ConfigParser, and I believe I am doing it correctly according to the docs , but cannot seem to get it to work. Can someone assist? import ConfigParser parser =…
Bill Swearingen
  • 634
  • 2
  • 8
  • 17
7
votes
4 answers

Keep ConfigParser output files sorted

I've noticed with my source control that the content of the output files generated with ConfigParser is never in the same order. Sometimes sections will change place or options inside sections even without any modifications to the values. Is there a…
JcMaco
  • 1,258
  • 3
  • 16
  • 31
6
votes
1 answer

python configparser writing to defaults section

i'm using the configparser module in python to read and write some .ini style files. i want to be able to create and write to the DEFAULTS section, however, it appears to be hardcoded to not allow the creation of such a section. is it possible? or…
yee379
  • 6,498
  • 10
  • 56
  • 101
6
votes
2 answers

How to read a config file with Python's configparser?

I'm working on reading an external config file in Python(3.7) using the module configparser. Here is my sample configuration file config.ini [ABC] ch0 = "C:/Users/utility/ABC-ch0.txt" ch1 = "C:/Users/utility/ABC-ch1.txt" [settings] script =…
Pbch
  • 179
  • 2
  • 4
  • 12
6
votes
1 answer

What is difference between read and read_file in configparser in Python 3?

I am wondering what is difference in usage of read and read_file in configparser. As far as I have tested config_parser = configparser.ConfigParser() config_parser.read(config_file) and config_parser =…
Manish Jindal
  • 109
  • 1
  • 8
6
votes
3 answers

Argparse: defaults from file

I have a Python script which takes a lot of arguments. I currently use a configuration.ini file (read using configparser), but would like to allow the user to override specific arguments using command line. If I'd only have had two arguments I'd…
shayelk
  • 1,606
  • 1
  • 14
  • 32
6
votes
2 answers

Don't understand this ConfigParser.InterpolationSyntaxError

So I have tried to write a small config file for my script, which should specify an IP address, a port and a URL which should be created via interpolation using the former two variables. My config.ini looks like this: [Client] recv_url :…
KyuMirthu
  • 377
  • 3
  • 13
6
votes
1 answer

When reading multiple config files, ConfigParser overwrites previous files, why?

So I wanted to start by saying I have been looking through out SO for an answer to this, and haven't been able to find anything useful. I've also looked through Python's docs and failed to find something useful. My last question was slightly lazy…
ordanj
  • 361
  • 1
  • 8
  • 19
6
votes
1 answer

specifying the same option multiple times with ConfigParser

I would like to read a configuration file with the python ConfigParser module: [asection] option_a = first_value option_a = second_value And I want to be able to get the list of values specified for option 'option_a'. I tried the obvious…
mathieu
  • 2,954
  • 2
  • 20
  • 31
6
votes
3 answers

How to remove spaces while writing in INI file- Python

I am using a file and i have one section named DIR in which it contain the paths. EX: [DIR] DirTo=D:\Ashish\Jab Tak hai Jaan DirBackup = D:\Parser\ERICSSON_CSCORE_STANDARD_VMS\Backup ErrorDir =…
Vipin Pulyani
  • 117
  • 1
  • 3
  • 7
5
votes
4 answers

How to load a configuration file in Python and be able to access values using dot notation (attributes)?

I am looking for a solution that would allow me be use attributes for a config file data. I would like to be able to do something like this: config = Config('config.ini') print config.section1.user print config.section2.password I do know the…
sorin
  • 161,544
  • 178
  • 535
  • 806