【发布时间】:2016-09-20 22:43:29
【问题描述】:
这是我所拥有的:
import bz2
compressionLevel = 9
source_file = '/foo/bar.txt' #this file can be in a different format, like .csv or others...
destination_file = '/foo/bar.bz2'
tarbz2contents = bz2.compress(source_file, compressionLevel)
fh = open(destination_file, "wb")
fh.write(tarbz2contents)
fh.close()
我知道 bz2.compress 的第一个参数是一个数据,但这是我发现的用来阐明我需要什么的简单方法。
我知道 BZ2File,但是我找不到任何使用 BZ2File 的好例子。
【问题讨论】:
标签: python compression bzip2