2.15 创建压缩包
1 zipfile.ZipFile('压缩包.zip','w') .write(file)
创建压缩包并加入文件
#coding=utf-8
import zipfile
file_lst=['demo1.py','demo2.py','demo3.py','demo4.py']
with zipfile.ZipFile('压缩包.zip','w') as zipobj: #将demo1-4加入压缩包
for file in file_lst:
zipobj.write(file)
2,zipfile.ZipFile('压缩包.zip','a') .write(file)
在压缩包中追加文件
#coding=utf-8 import zipfile with zipfile.ZipFile('压缩包.zip','a')as zipobj: #在压缩中追加文件 zipobj.write('demo5.py')