码迷,mamicode.com
首页 > 编程语言 > 详细

day6-python-压缩解压

时间:2016-06-21 22:42:38      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:

压缩解压包

#导入模块
import zipfile
#新建压缩包并将db与ooo.xml压缩到文件中
z = zipfile.ZipFile(laxi.zip,w)
z.write(db)
z.write(ooo.xml)
z.close()

#解压以读的方式打开laxi.zip文件
z = zipfile.ZipFile(laxi.zip,r)
#并将文件解压到指定路径
z.extractall(path = rC:\Users\liguangxu\Desktop)
#将指定文件解压到指定路径
z.extract(db,path = rC:\Users\liguangxu\Desktop)
z.close()
 1 #tarfile模块
 2 import tarfile
 3 #将your.tar文件以写的方式打开,并压缩添加bbs.log文件
 4 tar = tarfile.open(your.tar,w)
 5 tar.add(/Users/liguangxu/Desktop/a.txt,arcname= bbs.log)
 6 tar.close()
 7 
 8 
 9 #解压
10 tar = tarfile.open(your.tar,r)
11 tar.extractall()#可设置解压地址
12 tar.close()

 

day6-python-压缩解压

标签:

原文地址:http://www.cnblogs.com/liguangxu/p/5605177.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!