[Tutor] file.read() doesn't give full contents of compressed files

Barton David David.Barton at nottingham.ac.uk
Tue Feb 20 13:09:07 CET 2007

I'm really confused, and I hope somebody can explain this for me...
I've been playing with compression and archives, and have some .zip,
.tar, .gz and .tgz example files to test my code on.
I can read them using either zipfile, tarfile, gzip or zlib, and that's
fine. But just reading them in 'raw' doesn't give me the whole string of
(compressed) bytes.
len( file("mytestfile","r").read() ) != os.path.getsize("mytestfile")
Not even close, in fact. It seems like file.read() just stops after
reading a small portion of each example file, but why would that happen?
And what could I do if I wanted to read in the entire (compressed)
contents as a string?
thanks for any insight,
Dave (using Python 2.4 and windows)

This message has been checked for viruses but the contents of an attachment
may still contain software viruses, which could damage your computer system:
you are advised to perform your own checks. Email communications with the
University of Nottingham may be monitored as permitted by UK legislation.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070220/4793c3b8/attachment.htm 

More information about the Tutor mailing list