最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
python 实现tar文件压缩解压的实例详解
时间:2017-08-21 编辑:猪哥 来源:一聚教程网
压缩文件:
importtarfile importos deftar(fname): t=tarfile.open(fname+".tar.gz","w:gz") forroot,dir, filesinos.walk(fname): printroot,dir, files forfileinfiles: fullpath=os.path.join(root,file) t.add(fullpath) t.close() if__name__=="__main__": tar("del")
解压:
importtarfile importos defuntar(fname, dirs): t=tarfile.open(fname) t.extractall(path=dirs) if__name__=="__main__": untar("del.tar.gz",".")dirs参数为保存的目标文件的路径。
相关文章
- Golang ProtoBuf的基本语法详解 10-20
- Python识别MySQL中的冗余索引解析 10-20
- Python+Pygame绘制小球代码展示 10-18
- Python中的数据精度问题介绍 10-18
- Python随机值生成的常用方法介绍 10-18
- python3解压缩.gz文件分析 09-27