[Python] Python3 ZipFile how to write non-utf8 filename to archive by using writestr function

Discussão em 'Python' iniciado por Stack, Junho 24, 2025.

  1. Stack

    Stack Membro Participativo

    I am writing something like auto-compress files and upload to server, and I'm using writestr to directly write bytes to ZipFile from memory. But for historical problems, I need to make it display properly on some Windows PC with GBK encoding.

    Python3's str encoding is default utf-8. I want to know how to write the correct byte stream for the filename, the content can work with utf-8 so no need to care file content.

    I need a code sample. Thanks. Any solution is acceptable like new a class inherit it.

    Continue reading...

Compartilhe esta Página