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 even advised to do this?
You don't have to create the DEFAULT section, it already exists. You can set values in it right away.
config = ConfigParser.RawConfigParser()
config.set('DEFAULT', 'name2', 'value2')
with open('file.conf', 'wb') as cf:
config.write(cf)
The values you set as defaults when creating the ConfigParser instance will also get written to the DEFAULT section, as wim noted.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With