ConfigParser : overwrite ?
cantabile
cantabile.03 at wanadoo.fr
Sun Jul 17 12:01:19 EDT 2005
Hi, I'm trying and updating an .ini file with ConfigParser but each time
I call 'write', it appends the whole options another time to the file.
For example :
Here's the inital ini file
[section1]
foodir: %(dir)s/whatever
dir: foo
Here's my code :
filename = ...
config = ConfigParser.ConfigParser()
config.read(filename)
config.set('section1', 'dir', 'anotherdir')
f = open(filename, 'r+')
config.write(f)
f.close()
Then I get :
[section1]
foodir: %(dir)s/whatever
dir: anotherdir
[section1]
foodir: %(dir)s/whatever
dir: foo
I tried also with 'w', 'w+', 'a' ...
What's the correct way to avoid this ?
More information about the Python-list
mailing list