[python-win32] Problem writing ini file with ConfigParser
Tony Cappellini
tony at tcapp.com
Wed Apr 21 02:17:41 EDT 2004
At 08:40 PM 4/20/2004, Tony Meyer wrote:
> > 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
I knew that. I just wanted to see if anyone else was paying attention :-)
(obviously you are. Well done !!)
believe it or not, I have written to files before this :-))
More information about the Python-win32
mailing list