error in ConfigParser

pipehappy pipehappy at gmail.com
Tue Jun 27 22:35:06 EDT 2006


Hello everyone:

I came across the module ConfigParser and can use it correctly.

import ConfigParser
fp = open('test.cfg','w+')
config = ConfigParser.ConfigParser()
config.readfp(fp)
config.add_section('test')
config.set('test', 'haha', 'hehe')
print config.sections()
config.write(fp)

['test']
Traceback (most recent call last):
  File "configparser.py", line 8, in ?
    config.write(fp)
  File "C:\Python24\lib\ConfigParser.py", line 369, in write
    fp.write("[%s]\n" % section)
IOError: (0, 'Error')

I trace into the module and when executing the line "fp.write("[%s]\n"
% section)", I find every parameter is correct: fp is still a open file
object and section is 'test', I may miss something, but I just cannot
figure it out. Can someone tell me what's going wrong here?

Thanks




More information about the Python-list mailing list