Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #100208

Re: Reading lines of text from 7z compressed files in Python

From srinivas devaki <mr.eightnoteight@gmail.com>
Newsgroups comp.lang.python
Subject Re: Reading lines of text from 7z compressed files in Python
Date 2015-12-10 00:42 +0530
Message-ID <mailman.99.1449688408.12405.python-list@python.org> (permalink)
References <CAPv3ojWnWT3jWPk5uauu9Oo+p=zQP2Fawho5NFa9CZAFxP3h4A@mail.gmail.com>

Show all headers | View raw


On Dec 9, 2015 3:07 PM, "Anmol Dalmia" <dalmia.anmol@gmail.com> wrote:
>
>
> I wish to use the native LZMA library of Python 3.4 for faster performance
> than any other third- party packages. Is it possible to do so?
>

you can check the source of lzma module main compression and decompression
algorithms were written in c. so obviously you will get faster performance.
In [21]: import _lzma

In [22]: _lzma.__file__
Out[22]:
'/home/eightnoteight/.anaconda3/envs/snakes3.4.3/lib/python3.4/lib-dynload/_
lzma.cpython-34m.so'


and regarding your problem, here's a simple example on how you can read
line by line of your compressed 7z text file.


import lzma
with lzma.open('test.7z', 'w') as lf:
    lf.write(b'123\n'*1000)
with lzma.open('test.7z', 'r') as lf:
    arr = list(lf)
print(len(arr))
print(set(arr))
print(arr[0])
print(arr[0].decode('utf-8'))

[gist] https://gist.github.com/38681cad88928b089abb

later you can even extract that test.7z with 7z command line client with
(7z x test.7z)

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Reading lines of text from 7z compressed files in Python srinivas devaki <mr.eightnoteight@gmail.com> - 2015-12-10 00:42 +0530

csiph-web