[python-win32] Problem writing ini file with ConfigParser

Tony Meyer t-meyer at ihug.co.nz
Tue Apr 20 23:40:56 EDT 2004


> After sifting through the docs for ConfigPArser, and manually 
> banging in a script in PythonWin, the ConfigParser is getting 
> an exception during the write, I don't understand what the problem is
> 
> I've gone in with edit, and changed the file, and saved it, 
> so admin rights and read only don't sem to be a problem, from 
> the editor.
> 
> cfg=ConfigParser.ConfigParser()
> fp=open(r"c:\winnt\system32\gpib.ini")
> cfg.readfp(fp)
> cfg.read(r"c:\winnt\system32\gpib.ini")
[...]
> cfg.write(fp)

You're passing a file opened only for reading to .write().  You'll need to
either open for both reading and writing, or (better) close the file after
reading, and then open it again for writing.

=Tony Meyer




More information about the Python-win32 mailing list