gzip.GzipFile (was Re: Don't you just love writing this sort of thing :))
MRAB
google at mrabarnett.plus.com
Mon Dec 8 09:21:40 EST 2008
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.
>
> Also, making a decision based on the .gz part of the name isn't
> always correct -- you miss files named foo.Z and similar.
>
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.
More information about the Python-list
mailing list