我知道有一个叫pylzma的模块。但它只支持lzma,不支持lzma2。
我目前的解决方案是使用subprocess.call()调用7z程序。
有没有更好的方法?
发布于 2016-09-30 12:50:58
你可以使用backports.lzma,更多信息请参见:Python 2.7: Compressing data with the XZ format using the "lzma" module
然后,这只是一个简单的问题,例如:
from backports import lzma
with open('hello.xz', 'wb') as f:
f.write(lzma.compress(b'hello', format=lzma.FORMAT_XZ))或更简单(默认为XZ格式):
with lzma.open('hello.xz', 'wb') as f:
f.write(b'hello')有关使用详情,请参阅http://docs.python.org/dev/library/lzma.html。
https://stackoverflow.com/questions/16477650
复制相似问题