Unzip: Memory Error

David Bolen db3l.net at gmail.com
Thu Aug 30 15:25:25 EDT 2007


mcl <mcl.office at googlemail.com> writes:

> pseudo code
>
> zfhdl = zopen(zip,filename)          # Open File in Zip Archive for
> Reading
>
> while True:
>     ln = zfhdl.readline()            # Get nextline of file
>     if not ln:                       # if EOF file
>       break
>     dealwithline(ln)                 # do whatever is necessary with
> file
> zfhdl.close
>
> That is probably over simplified, and probably wrong but you may get
> the idea of what I am trying to achieve.

Do you have to process the file as a textual line-by-line file?  Your
original post showed code that just dumped the file to the filesystem.
If you could back up one step further and describe the final operation
you need to perform it might be helpful.

If you are going to read the file data incrementally from the zip file
(which is what my other post provided) you'll prevent the huge memory
allocations and risk of running out of resource, but would have to
implement your own line ending support if you then needed to process
that data in a line-by-line mode.  Not terribly hard, but more
complicated than my prior sample which just returned raw data chunks.

Depending on your application need, it may still be simpler to just
perform an extraction of the file to temporary filesystem space (using
my prior code for example) and then open it normally.

-- David



More information about the Python-list mailing list