using ConfigParser wrong?

D

David Rysdam

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,771
Messages
2,569,587
Members
45,098
Latest member
KetoBaseReview
Top