【发布时间】:2023-08-31 05:04:01
【问题描述】:
我知道有一个名为 pylzma 的模块。但它只支持lzma,不支持lzma2。
我目前的解决方案是使用subprocess.call()调用7z程序。
有没有更好的办法?
【问题讨论】:
标签: python compression 7zip lzma
我知道有一个名为 pylzma 的模块。但它只支持lzma,不支持lzma2。
我目前的解决方案是使用subprocess.call()调用7z程序。
有没有更好的办法?
【问题讨论】:
标签: python compression 7zip lzma
您可以使用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。
【讨论】: