支持中文编码
from zipfile import ZipFile
def support_gbk(zip_file):
name_to_info = zip_file.NameToInfo
# copy map first
for name, info in name_to_info.copy().items():
real_name = name.encode('cp437').decode('gbk')
if real_name != name:
info.filename = real_name
del name_to_info[name]
name_to_info[real_name] = info
return zip_file
解压压缩包
def decompression(path):
extract_to = os.path.dirname(path) # 获取zip文件的目录路径
with support_gbk(ZipFile(path)) as zfp: # 解压当前压缩包
zfp.extractall(extract_to)
标签:info,real,name,zip,Python,乱码,path,压缩包
From: https://www.cnblogs.com/wanghong1994/p/17972044