Help with capturing error
Diez B. Roggisch
deets at nospam.web.de
Thu Nov 27 16:23:56 EST 2008
tekion schrieb:
> Hello,
> I am getting the following error and my script is bailing out because
> of it. I have tried capturing it but it does not seem to work. Below
> is the error:
>
> ValueError: I/O operation on closed file
>
>
> the above error is received when, the following code snippet is
> executed:
> try:
> 117 self.xml_file.close()
> 118 except ValueError:
> 119 print "file, %s is already closed" % self.seek_file
>
> Any idea why line 118, is not capturing the error? Thanks.
This is not valid python - it obviously isn't indented properly.
The following piece of code works flawlessly for me:
outf = open("/tmp/test.dat", "w")
outf.write("foo")
outf.close()
try:
outf.close()
except ValueError:
pass
Diez
More information about the Python-list
mailing list