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

Jorgen Grahn grahn+nntp at snipabacken.se
Mon Dec 8 03:13:59 EST 2008


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.

Also, making a decision based on the .gz part of the name isn't
always correct -- you miss files named foo.Z and similar.

/Jorgen

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



More information about the Python-list mailing list