当前位置:天才代写 > tutorial > Python教程 > python压缩和读取.tar.bz2格式的压缩包

python压缩和读取.tar.bz2格式的压缩包

2018-05-17 08:00 星期四 所属: Python教程 浏览:409

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

python">#压缩文件夹为 .tar.bz2
import tarfile
import bz2
archive = 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 compress
archive.close()

#解压一个.tar.bz2
import tarfile
import bz2
archive = 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()

标签:python

 

    关键字:

天才代写-代写联系方式