Problem with zipfile and newlines

Duncan Booth duncan.booth at invalid.invalid
Mon Mar 10 08:14:47 EDT 2008


"Neil Crighton" <neilcrighton at gmail.com> wrote:

> I'm using the zipfile library to read a zip file in Windows, and it
> seems to be adding too many newlines to extracted files. I've found
> that for extracted text-encoded files, removing all instances of '\r'
> in the extracted file seems to fix the problem, but I can't find an
> easy solution for binary files.
> 
> The code I'm using is something like:
> 
> from zipfile import Zipfile
> z = Zipfile(open('zippedfile.zip'))
> extractedfile = z.read('filename_in_zippedfile')
> 
> I'm using Python version 2.5.  Has anyone else had this problem
> before, or know how to fix it?
> 
> Thanks,
> 
Zip files aren't text. Try opening the zipfile file in binary mode:

   open('zippedfile.zip', 'rb')




More information about the Python-list mailing list