Silly question about ungzipping a file

Alex Martelli aleax at
Fri Sep 27 03:34:40 EDT 2002

Lemniscate wrote:
>>>> import gzip
>>>> myFile ='LL_tmpl.gz')
>>>> file('output.txt', 'w').write(
> Now, is there any way to do this so that less memory is used?  I mean,

import shutil
shutil.copyfileobj(myFile, open('output.txt', 'w'))

> 129MB.  I'm sure I'm just missing something simple, but why is that?

I think the reason you're missing this simple something is that you
are not entirely familiar with Python's rich standard library -- a
defect common to us all (I don't recall _every_ useful module either:-).

A partial help is /F's "Python Standard Library" (O'Reilly) -- it
won't magically infuse you with knowledge of every such module, but
by giving at least one example script for each module in the
library (all in a remarkably concise 280 pages!) it makes it quite
a bit more likely that more modules will stay in your subconscious
memory.  Python's online reference, Beazley's New Riders book, my
Nutshell when it comes (the delay ain't my fault THIS time - the
complete, technically-revised draft is currently in the editor's
hands!-), each give a different perspective on Python's standard
library, and enhance the likelihood that you'll know where to find
excellent code ripe for reuse.  Probably the best single piece of
advice is the one in the Python online docs -- "sleep with the
Library Reference under your pillow" (and use a thin pillow, so that
the knowledge has an easier time filtering up into your brain:-).


More information about the Python-list mailing list