6

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?

Niek de Klein
  • 8,524
  • 20
  • 72
  • 143
  • 1
    Unfortunately there is no module that handles 7z files. You may want to use the `subprocess` module to get the output from 7z and process it as you like: `subprocess.getoutput( '7z l archive.7z' )` – Marcus Mar 18 '16 at 20:41

1 Answers1

5

There is a built in module in Python >= 3.3: http://docs.python.org/3.3/library/lzma

And there is also a backport of the module on the PyPI: https://pypi.python.org/pypi/backports.lzma

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

Viktor Kerkez
  • 45,070
  • 12
  • 104
  • 85
  • 3
    please note that while 7z uses LZMA as its workhorse to perform the compression, 7z and LZMA are not the same thing. I have explained this in detail in [this post](http://stackoverflow.com/a/36093803/1233513) – Marcus Mar 18 '16 at 20:40