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()

你可能感兴趣的:(python)