Your indentation is a bit hard to read in this format, but it looks like the
"for subkey in uninstall" block needs to be inside the "with open" block.
When the "with open" block exits, the file is no longer open.  Thus writing
to a closed file will fail.


On Mon, Mar 22, 2010 at 4:22 PM, travel europe <europe_tra...@hotmail.com>wrote:

>  Hello,
>
> I am getting the following error "ValueError: I/O operation on closed file"
> when running a module to pull data from the Windows registry.
>
> The code is as follows:
>
> <code>
> import csv
> from winsys import registry
>
> key =
> r"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
> fields = ["DisplayName", "Comments", "InstallDate"] # add to as required
>
> uninstall = registry.registry (key)
> with open ("installed.txt", "wb") as f:
>  writer = csv.writer (f)
>  writer.writerow (fields)
> for subkey in uninstall:
>  info = dict (subkey.values ())
>  writer.writerow ([info.get (field) for field in fields])
> <code>
>
> <error message>
> The error message is as follows:
> Traceback (most recent call last):
>   File "C:\Python26\tim.py", line 13, in <module>
>     writer.writerow ([info.get (field) for field in fields])
> ValueError: I/O operation on closed file
> <error message>
>
> Any ideas on how to rectify this problem? Thanks!
>
> ------------------------------
> Hotmail is redefining busy with tools for the New Busy. Get more from your
> inbox. Sign up 
> now.<http://www.windowslive.com/campaign/thenewbusy?ocid=PID27925::T:WLMTAGL:ON:WL:en-US:WM_HMP:032010_2>
>
>
_______________________________________________
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to