是否有等效于.7z文件的gzip.open()? [英] Is there an equivalent of gzip.open() for .7z files?

查看:123
本文介绍了是否有等效于.7z文件的gzip.open()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须经常搜索几个.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

是否有模块/

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上还有一个模块的反向端口: 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二进制文件中的PyLZMA软件包)

(If you're on Windows and you don't want to compile it by yourself you can use the PyLZMA package from Unofficial Windows Binaries for Python).

这篇关于是否有等效于.7z文件的gzip.open()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆