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()