83-tarfile的使用

tarfile的使用:

import tarfile

# 压缩文件的方法
tar = tarfile.open('./etc/demo.tar.gz', 'w:gz') # gzip压缩
tar.add('./etc/hosts')
tar.add('./etc/passwd')

tar.close()
# tar tvzf /tmp/demo.tar.gz
# 解压文件的方法
tar = tarfile.open('./etc/demo.tar.gz', 'r')
tar.extractall(path='./tarfile') # 解压所有文件到当前目录
tar.close()

结果输出:

转载于:https://www.cnblogs.com/hejianping/p/11095100.html

猜你喜欢

转载自blog.csdn.net/weixin_34037515/article/details/94285208
83
今日推荐