zipfile module and exceptions

nobody nobody at nowhere.near.here
Mon Jan 27 11:47:17 EST 2003


I have following simple code using zipfile module:

            try:
                z = zipfile.ZipFile(file, "r")

                if z.testzip() is None:
                    self.listBox2.Append(file)
                else:
                    self.listBox3.Append(file)
                z.close()

            except (IOError, zipfile.BadZipfile):
                self.listBox3.Append(file)
                z.close()

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?






More information about the Python-list mailing list