How to "gunzip-iterate" over a file?

Paul Rubin http
Wed Jul 29 21:04:47 EDT 2009


Robert Kern <robert.kern at gmail.com> writes:
> f = gzip.open('filename.gz')
> for line in f:
>      print line

or use f.read(nbytes) to read n uncompressed bytes from f.  Note that
the standard iterator (which iterates over lines) can potentially
consume an unbounded amount of memory if the file contains no newlines.



More information about the Python-list mailing list