[Tutor] GzipFile has no attribute '__exit__'

Kent Johnson kent37 at tds.net
Mon Nov 16 13:39:33 CET 2009

On Mon, Nov 16, 2009 at 7:15 AM, Sander Sweers <sander.sweers at gmail.com> wrote:

> This triggered my to dig into this a bit. This is not fixed untill
> python 3.1 but seems easilly added to the ZipFile class. My attempt to
> backport this from python 3.1's gzip.py below seems to work.
> Greets
> Sander
> import gzip
> class myGzipFile(gzip.GzipFile):
>    def __enter__(self):
>        if self.fileobj is None:
>            raise ValueError("I/O operation on closed GzipFile object")
>        return self
>    def __exit__(self, *args):
>        self.close()

You might want to report this as a bug against 2.6 and submit this
change as a proposed fix. It's easy to do, see

You could submit your change right in the body of the report if you
don't want to make a diff file. You could suggest an update to the
docs as well.


More information about the Tutor mailing list