Question:
I have a zip that, inside it, there are several files to be unzipped. So far so good, I'm using the following method to unzip it:?
with closing(z), zipfile.ZipFile(io.BytesIO(z.content)) as myzip:
myzip.extractall(local_path)
However I came across the situation that inside the zip there is a file with unicode, for example:
- myfile.wav
- myfile2.wav
- my§ile.wav
How can I handle these files, to unzip them correctly?
Answer:
To work with Unicode characters, it is necessary to add a functional comment type in the script header to avoid this error. I'm talking about # – – coding: utf-8 – -, used for this case. Here's an example, for Python 2.7:
– – coding: utf-8 – –
with closing(z), zipfile.ZipFile(io.BytesIO(z.content)) as myzip: myzip.extractall(local_path)
The sharp is not coming out to indicate that it is a comment, nor the asterisks in the answer between the hyphens I don't know why when I write, but consider them when writing the program.