python压缩和读取.tar.bz2格式的压缩包,python.tar.bz2,python可以通过ta


python可以通过tarfile模块压缩和解压.tar.bz2包

#压缩文件夹为 .tar.bz2import tarfileimport bz2archive = tarfile.open('myarchive.tar.bz2','w:bz2')archive.debug = 1           # Display the files beeing compressed.archive.add(r'd:\myfiles')  # d:\myfiles contains the files to compressarchive.close()#解压一个.tar.bz2import tarfileimport bz2archive = tarfile.open('myarchive.tar.bz2','r:bz2')archive.debug = 1    # Display the files beeing decompressed.for tarinfo in archive:    archive.extract(tarinfo, r'd:\mydirectory') # d:\mydirectory is where I want to uncompress the files.archive.close()

评论关闭