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 = c0>>> p = ConfigParser.SafeConfigParser()
>>> s = open('a.ini', 'r+')
>>> p.readfp(s)
>>> p.sections()
['a']
>>> p.remove_section('a')
True
>>> p.sections()
[]
>>> p.write(s)
>>> s.close()
>>> os.system("cat a.ini")
[a]
b = c0
>>>
It appears that the remove_section() happens only in-memory and when asked to write back the results to the ini file, there is nothing to write.
Any ideas on how to remove a section from the ini file and persist it?
Is the mode that I'm using to open the file incorrect? I tried with 'r+' & 'a+' and it didn't work. I cannot truncate the entire file since it may have other sections that shouldn't be deleted.