'How can I use non ASCII file names in a zipped file and extract them using ZipFile in Python 2.4?
I have a file öl_och_ål_är_gott.txt inside a zip archive named öl_och_ål_är_gott.zip. The archive isn't created using zipfile. It could come from any software capable of creating a zip archive.
src = open(file_path, "rb" )
zip_file = ZipFile(src)
for info in zip_file.infolist():
print info.filename
...
prints out:
”l_och_†l_„r_gott.txt
How can I force zipfile to represent the name as I want it to be represented?
Solution 1:[1]
As the docs state, there is no official file name encoding for ZIP files. If you have Unicode file names (as in your case), you must convert them to byte strings in your desired encoding before passing them.
Though I don't know why it doesn't work for you.
>>> src = open('/Desktop/test.zip', 'rb')
>>> zip_file = zipfile.ZipFile(src)
>>> for info in zip_file.infolist():
... print info.filename
...
öl_och_ål_är_gott
On my Ubuntu box.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
