打包目录

1 #_*_coding:utf-8_*_
2 #__author__ = "csy"
3 import shutil
4 
5 shutil.make_archive("test","zip","D:/5")   #生成文件名test,格式zip,目录路径

另外也可以用zipfile模块,指定具体要压缩的文件

1 #_*_coding:utf-8_*_
2 #__author__ = "csy"
3 
4 import zipfile
5 z = zipfile.ZipFile("5.zip","w")
6 z.write("1.txt")
7 print("=========~~~~~~~~~~")
8 z.write("3.txt")
9 z.close()

解压

1 #_*_coding:utf-8_*_
2 #__author__ = "csy"
3 
4 import zipfile
5 z = zipfile.ZipFile("5.zip","r")
6 z.extractall()
7 z.close()

 

posted on 2017-07-23 18:49  csy113  阅读(346)  评论(0编辑  收藏  举报