I am writing a code in python. I have a confg file with following data:
[section1]
name=John
number=3
I am using ConfigParser module to add another section in this already existing confg file without overwriting it. But when I use below code:
config = ConfigParser.ConfigParser()
config.add_section('Section2')
config.set('Section2', 'name', 'Mary')
config.set('Section2', 'number', '6')
with open('~/test/config.conf', 'w') as configfile:
config.write(configfile)
it overwrites the file. I do not want to delete the previous data. Is there any way I can just add one more section? If I try to get and write the data of previous sections first, then it will become untidy as the number of sections will increase.