python-文件压缩和解压
Posted UnixFBI 运维特工
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python-文件压缩和解压相关的知识,希望对你有一定的参考价值。
import tarfile #压缩 tar = tarfile.open(‘your.tar‘,‘w‘) tar.add(‘ooo.xml‘,arcname=‘ooo.xml‘) tar.close() #解压全部文件 tar = tarfile.open(‘your.tar‘,‘r‘) tar.extractall() tar.close() #解压指定文件 for item in tar.getmembers(): print(item,type(item)) obj = tar.getmember(‘ooo.xml‘) tar.extract(obj) tar.close()
以上是关于python-文件压缩和解压的主要内容,如果未能解决你的问题,请参考以下文章