gzip.GzipFile (was Re: Don't you just love writing this sort of thing :))

Jorgen Grahn grahn+nntp at snipabacken.se
Tue Dec 9 09:39:43 CET 2008

On Mon, 08 Dec 2008 14:21:40 +0000, MRAB <google at mrabarnett.plus.com> wrote:
> Jorgen Grahn wrote:
>> On Sat, 06 Dec 2008 10:01:10 +0000, Arnaud Delobelle <arnodel at googlemail.com> wrote:
>> ...
>>> Why use (open, gzp.GzipFile)[Entry.endswith(".gz")] when we have had
>>> contitional expressions for a few years now?  Instead, you can write
>>>     (gzip.GzipFile if entry.endswidth(".gz") else open).
>>> I think it will be faster (as it doesn't require the construction of a
>>> tuple and then the retrieval of one of its elements) and clearer.
>> Even clearer would be if gzip.Gzipfile could (optionally) read
>> non-gzipped files and file-like objects, like the gzip Unix commands
>> zcat -f, zgrep and so on.

> gzip is for reading gzipped files. IMHO it would be better to have a 
> de-archive module which uses the gzip, tarfile, etc, modules as necessary.

Not tarfile, since that's usually a container for many files.

But ok, maybe you are right about placing it in a different module
-- even though it's fairly common for Unix application to accept plain
files, gzipped files and nothing else.

Note that such a module should handle reading sys.stdin and other
non-disk files. That's a bit tricky, because when you realize that you
guessed wrong on the format, you have already consumed and discarded
some of the data.

I started looking at such a module a year ago, but never finished it.


  // Jorgen Grahn <grahn@        Ph'nglui mglw'nafh Cthulhu
\X/     snipabacken.se>          R'lyeh wgah'nagl fhtagn!

More information about the Python-list mailing list