[Tutor] Fw: Reading gzip files

Kent Johnson kent37 at tds.net
Tue Dec 16 18:06:25 CET 2008


On Tue, Dec 16, 2008 at 11:29 AM, Dinesh B Vadhia
<dineshbvadhia at hotmail.com> wrote:

> What I'd like to do is ... when an "IOError: CRC check failed" error happens
> then close the offending file and move on to the next file in the list.  How
> do I achieve this with this particular type of error?

You can catch IOError specifically or you can catch all exceptions
using try / except / finally. To trap all exceptions and continue with
the next file:

for ziparchive in list_zipfiles:
    zfile = gzip.GzipFile(zipfolder + ziparchive, "r")
    try:
        for line in zfile:
            fw.write(line)
    except:
        pass
    finally:
        zfile.close()
fw.close()

Kent


More information about the Tutor mailing list