2006-11-02

ZipFile interface slightly shocked me

Yesterday I needed to read some files from ZIP archives in my program on Python. So I read the zipfile.ZipFile class documentation and found that the only way to read the archived file content is read() method which returns bytes of the file. I think "Hmm, how is it? I really need to try some examples":

So the whole file was read into the b variable! But what if I only need to read some bytes from the file header or read it line by line for example? I was slightly shocked. Why ZipFile don't have a method which returns a file-like object?