问题描述
我必须经常搜索几个 .7z(用 LZMA 压缩)文件.我没有足够的内存来同时解压缩它们或将存档更改为 .gz.在我解压一个的那一刻,搜索我需要的,删除提取的内容,解压下一个.我想以与 gzip 相同的方式浏览档案:
I have to frequently search through a couple of .7z (zipped with LZMA) files. I don't have enough memory to have them unpacked at the same time or to change the archive to .gz. At the moment I unpack one, search for what I need, delete what was extracted, unpack the next. I want to go through the archives in the same way as with gzip:
f = gzip.open('archive.gz')
for i in f:
do stuff
是否有使用 .7z 文件执行此操作的模块/方法?
Is there a module/way to do this with .7z files?
推荐答案
Python >= 3.3 有一个内置模块:http://docs.python.org/3.3/library/lzma
There is a built in module in Python >= 3.3: http://docs.python.org/3.3/library/lzma
而且 PyPI 上还有一个模块的 backport:https://pypi.python.org/pypi/backports.lzma
And there is also a backport of the module on the PyPI: https://pypi.python.org/pypi/backports.lzma
(如果您在 Windows 上并且不想自己编译它,您可以使用 Python 的非官方 Windows 二进制文件).
这篇关于.7z 文件是否有相当于 gzip.open() 的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!