zipfile module and exceptions
nobody
nobody at nowhere.near.here
Mon Jan 27 13:16:21 EST 2003
Thank you, I did overlook the else: possibility.
"Skip Montanaro" <skip at pobox.com> wrote in message
news:mailman.1043687396.19493.python-list at python.org...
> >> The problem is that in the except clause the z.close() fails
because
> >> the z is not known. Am I not supposed to close the file in the case
> >> of IOError? If not the solution is simple... Any ideas?
>
> Try something like this instead:
>
> try:
> z = zipfile.ZipFile(file, "r")
> except (possible creation errors here):
> print >> sys.stderr, "Can't open zipfile %s for reading" % file
> else:
> if z.testzip() is None:
> self.listBox2.Append(file)
> else:
> self.listBox3.Append(file)
> z.close()
>
> Skip
>
More information about the Python-list
mailing list