vlei 发表于 2017-4-23 07:34:04

python compress note

You call tarfile.open with mode='w:gz', meaning "Open for gzip compressed writing."
You'll probably want to end the filename (the name argument to open) with .tar.gz, but that doesn't affect compression abilities.
BTW, you usually get better compression with a mode of 'w:bz2', just like tar can usually compress even better with bzip2 than it can compress with gzip.


import tarfile
tar = tarfile.open("sample.tar.bz2","w:bz2")
for name in["file1","file2","file3"]:
tar.add(name)
tar.close()
页: [1]
查看完整版本: python compress note