Python - zipfile solve garbage problem

  Recent zipfile carried out after the unbundling process encountered uncomfortable questions, unpack the file name is garbled. The following brief summary:

  First, because the garbage is certainly not the same as the decoding mode, zipfile using utf-8 and cp437 both encoding, because guess here is crooked nuts release.

  Here in fact change it directly in the source code on it

  Directly in the source file to bring up the search box search "cp437" to find

1             if flags & 0x800:
2                 # UTF-8 file names extension
3                 filename = filename.decode('utf-8')
4             else:
5                 # Historical ZIP filename encoding
6                 # filename = filename.decode('cp437')
7                 filename = filename.decode('gbk')
            if zinfo.flag_bits & 0x800:
                # UTF-8 filename
                fname_str = fname.decode("utf-8")
            else:
                # fname_str = fname.decode("cp437")
                fname_str = fname.decode("gbk")

  As long as these two can get rid of normal use

  Revelation:

  Normally we write programs using python users have written some things, just slightly altered copy it, but to expand the tool package seems to have one of the official and formal feeling, stepping through this pit, I think no matter who released the thing, is not for everyone, we should use alternative, after all, in any language and tools are designed to facilitate the development and improve the efficiency of only arise, not in accordance with the old rigid ideas to.

  

Guess you like

Origin www.cnblogs.com/ligaofeng/p/11280001.html