GzipFile as a Context manager

Discussion in 'Python' started by Mikolai Fajer, Nov 19, 2008.

  1. Is there a reason that the gzip.GzipFile class does not have __enter__
    and __exit__ methods that mimic those of the file object? I expected
    the following to work but it doesn't:

    import gzip
    with gzip.open('temp.gz', 'w') as fhandle:
    gzip.write('Hello world.')

    If there is no reason to avoid this behavior should I submit a bug
    report and a subsequent patch? Thanks!

    --

    -Mikolai Fajer-
     
    Mikolai Fajer, Nov 19, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Paulo da Silva

    A problem with GzipFile (BUG?)

    Paulo da Silva, Aug 14, 2004, in forum: Python
    Replies:
    0
    Views:
    293
    Paulo da Silva
    Aug 14, 2004
  2. Justin Guerin

    how to close a gzip.GzipFile?

    Justin Guerin, Apr 1, 2005, in forum: Python
    Replies:
    0
    Views:
    325
    Justin Guerin
    Apr 1, 2005
  3. Justin Guerin

    Re: how to close a gzip.GzipFile?

    Justin Guerin, Apr 1, 2005, in forum: Python
    Replies:
    1
    Views:
    349
    Sidharth
    Apr 1, 2005
  4. Matt
    Replies:
    0
    Views:
    245
  5. Brian Cole

    GzipFile(fileobj=sys.stdin) Why not?

    Brian Cole, Oct 10, 2008, in forum: Python
    Replies:
    0
    Views:
    321
    Brian Cole
    Oct 10, 2008
Loading...

Share This Page