Memory error reading a zip file in python
Question: I have a thread in which I am reading a zip file with
`zipfile.ZipFile().read()`, where I am getting a memory error.

I am aware that `read()` loads the entire file into memory. The size of file
after unzipping is more than 100MB. I also tried with
`zipfile.ZipFile().open().readlines()`, but it takes too much time.

Is there any way that I can read the file with speed without getting memory
error?


Answer: Assuming you're trying to read a zipped text file, you can treat the file-like
object returned by
[`ZipFile.open()`](http://docs.python.org/2/library/zipfile#zipfile.ZipFile.open)
as an iterator, and process it line-by-line...

    
    
    from zipfile import ZipFile
    
    zip = ZipFile('myzip.zip')
    stream = zip.open('myfile.txt')
    for line in stream:
        do_something_with(line)
    

