Reputation: 6762
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?
Upvotes: 6
Views: 4465
Reputation: 594
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.
Upvotes: 5