Skip to content

Instantly share code, notes, and snippets.

@Saberko
Created August 5, 2016 07:48
Show Gist options
  • Save Saberko/0782814d5c35c68ae926a793d4e42144 to your computer and use it in GitHub Desktop.
Save Saberko/0782814d5c35c68ae926a793d4e42144 to your computer and use it in GitHub Desktop.
解压非utf-8编码格式的压缩包避免乱码
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys
import zipfile
file = zipfile.ZipFile(sys.argv[1], "r");
for name in file.namelist():
utf8name=name.decode('gbk')
pathname = os.path.dirname(utf8name)
if not os.path.exists(pathname) and pathname!= "":
os.makedirs(pathname)
data = file.read(name)
if not os.path.exists(utf8name):
fo = open(utf8name, "w")
fo.write(data)
fo.close
file.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment