[Tutor] Reading .gz files
Steven D'Aprano
steve at pearwood.info
Fri Jul 29 15:36:28 CEST 2011
Hanlie Pretorius wrote:
> [code]
> import gzip
>
> f1 = 'GSMaP_MVK+.20050101.00.0.1deg.hourly.v484.gz'
> f2 = ''text.txt.gz'
> if1 = gzip.open(f1, 'rb')
> if2 = gzip.open(f2,'rb')
> try:
> print if1.read()
> print 'done with f1'
> print if2.read()
> print 'done with f2'
> finally:
> if1.close()
> if2.close()
> [/code]
>
> [output]
> done with f1
> Text to test gzip module.
> done with f2
> [/output]
> This seems to indicate that something is wrong with f1 (the GSMaP file - a
Are you sure it is an actual gzip file? You refer to gzip, 7-zip, and
unzip in your post -- these are all different compression formats. Just
because the file is *named* .gz doesn't necessarily mean it is a gzip file.
Try this:
if1 = gzip.open(f1, 'rb')
print repr(if1.read())
print if1.size, if1.crc, if1.name
and see what they say.
--
Steven
More information about the Tutor
mailing list