ubuntu zip文件乱码问题解决方案

之前上传了一个python2的,但是python2确实使用比较少了,于是我做了点修改,可以python3下使用。

#!usr/bin/env python3
import os 
import sys 
import zipfile 

print("processing File " + sys.argv[1] )
file = zipfile.ZipFile(sys.argv[1], "r"); 
for name in file.namelist(): 
    print("Extracting " + name )
    pathname = os.path.dirname(name) 
    if not os.path.exists(pathname) and pathname !="":
        os.makedirs(pathname) 
    data = file.read(name); 
    if not os.path.exists(name):
        fo = open(name, "wb")
        fo.write(data)
        fo.close()
file.close() 

有优化空间,大家可以做一些输出优化和体验优化,然后放到/usr/local/bin下即可全局使用。

猜你喜欢

转载自blog.csdn.net/u012939880/article/details/88943928