distinction between unzipping bytes and unzipping a file
ryandw at gmail.com
Fri Jan 9 20:49:23 CET 2009
In python, is there a distinction between unzipping bytes and
unzipping a binary file to which those bytes have been written?
The following code is, I think, an example of writing bytes to a file
and then unzipping...
decoded = base64.b64decode(datum)
#datum is a base64 encoded string of data downloaded from a web
f = open('data.zip', 'wb')
x = zipfile.ZipFile('data.zip', 'r')
After looking at the preceding code, the provider of the web service
gave me this advice...
"Instead of trying to create a file, take the unzipped bytes and get a
Unicode string of text from it."
If so, I'm not sure how to do what he's suggesting, or if it's really
different from what I've done.
I find that I am able to unzip the resulting data.zip using the unix
unzip command, but the file inside contains some FFFD characters, as
described in this thread...
I don't know if the unwanted characters might be the result of my
trying to write and unzip a file, rather than unzipping the bytes.
The file does contain a semblance of what I ultimately want -- it's
not all garbage.
Apologies if it's not appropriate to start a new thread for this. It
just seems like a different topic than how to deal with the resulting
Thanks for your help,
More information about the Python-list