1
以下是我有:如何在Python中用bzip2壓縮文件?
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的好例子。
大@Gerrat!第一個選項適合我。謝謝! – Lucas