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.<br>
<br><br><div class="gmail_quote">On Mon, Mar 22, 2010 at 4:22 PM, travel europe <span dir="ltr"><<a href="mailto:europe_travel@hotmail.com">europe_travel@hotmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div>
Hello,<br>
<br>
I am getting the following error "ValueError: I/O operation on closed file" when running a module to pull data from the Windows registry.<br>
<br>
The code is as follows: <br>
<br>
<code><br>
import csv<br>from winsys import registry<br>
<br>
key = r"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"<br>fields = ["DisplayName", "Comments", "InstallDate"] # add to as required<br>
<br>
uninstall = registry.registry (key)<br>with open ("installed.txt", "wb") as f:<br> writer = csv.writer (f)<br> writer.writerow (fields)<br>for subkey in uninstall:<br> info = dict (subkey.values ())<br>
writer.writerow ([info.get (field) for field in fields])<br><code><br>
<br>
<error message><br>
The error message is as follows:<br>
Traceback (most recent call last):<br> File "C:\Python26\tim.py", line 13, in <module><br> writer.writerow ([info.get (field) for field in fields])<br>ValueError: I/O operation on closed file<br>
<error message><br>
<br>
Any ideas on how to rectify this problem? Thanks!<br><div class="hm">                                            <br><hr>Hotmail is redefining busy with tools for the New Busy. Get more from your inbox. <a href="http://www.windowslive.com/campaign/thenewbusy?ocid=PID27925::T:WLMTAGL:ON:WL:en-US:WM_HMP:032010_2" target="_blank">Sign up now.</a></div>
</div>
<br></blockquote></div>