using ConfigParser wrong?

David Rysdam drysdam at ll.mit.edu
Mon Sep 20 10:05:42 EDT 2004


I have a file test.cfg:

[options]
option1=foo
option2=bar


I have a program testconfig.py:

import ConfigParser

config = ConfigParser.ConfigParser()
f = open('test.cfg')
config.readfp(f)
configList = config.items('options')
print configList
config.set('options', 'option3', 'baz')
config.write(f)


When I run this program, I get an error:

Traceback (most recent call last):
   File "./testconfig.py", line 11, in ?
     config.write(f)
   File "/usr/lib/python2.3/ConfigParser.py", line 363, in write
     fp.write("[%s]\n" % section)
IOError: [Errno 9] Bad file descriptor


Is .write() not right?  If not, how do I save the changed config to file?



More information about the Python-list mailing list