python-tarfile模块(82)
·
import tarfile
#压缩文件的方法
tar = tarfile.open('/tmp/demo.tar.gz','w:gz') #gzip压缩
tar.add('/etc/hosts') #添加要压缩的文件
tar.add('/etc/security')
tar.close()
#解压文件的方法
tar = tarfile.open('/tmp/demo.tar.gz','r:gz')
tar.extractall() #解压文件到当前目录
tar.close()更多推荐
所有评论(0)