python zip文件压缩和解压

压缩

import shutil

zipOutputName = "1234"  # 输出1234.zip
fileType = "zip"  # 文件类型zip
path = "."
fileName = "1234.txt" #源文件

shutil.make_archive(zipOutputName, fileType, path, fileName)

解压

import zipfile

zipfilePath = ("./1234.zip")
zip = zipfile.ZipFile(zipfilePath)
zip.extractall(".")
zip.close()
posted @ 2019-01-31 15:05  公众号python学习开发  阅读(407)  评论(0编辑  收藏  举报