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

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From srinivas devaki <mr.eightnoteight@gmail.com>
Newsgroups comp.lang.python
Subject Re: Reading lines of text from 7z compressed files in Python
Date Thu, 10 Dec 2015 00:42:41 +0530
Lines 35
Message-ID <mailman.99.1449688408.12405.python-list@python.org> (permalink)
References <CAPv3ojWnWT3jWPk5uauu9Oo+p=zQP2Fawho5NFa9CZAFxP3h4A@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
X-Trace news.uni-berlin.de OOc7jgKNqkwOhk0jCk1MvAh0A4vyZTZ30nmS5fHtxXQw==
Return-Path <mr.eightnoteight@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'received:209.85.223': 0.03; 'subject:text': 0.04; 'subject:Python': 0.05; 'so?': 0.07; 'cc:addr:python-list': 0.09; "'w')": 0.09; 'compression': 0.09; 'subject:files': 0.09; 'url:github': 0.09; 'python': 0.10; 'packages.': 0.15; "'r')": 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:Reading': 0.16; 'wrote:': 0.16; 'later': 0.16; 'obviously': 0.16; '&gt;': 0.18; 'email addr:gmail.com&gt;': 0.18; 'library': 0.20; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'file.': 0.22; 'cc:no real name:2**0': 0.22; 'dec': 0.23; 'import': 0.24; 'written': 0.24; 'header:In-Reply-To:1': 0.24; 'module': 0.25; 'example': 0.26; 'command': 0.26; 'message-id:@mail.gmail.com': 0.27; "skip:' 70": 0.29; 'skip:_ 10': 0.32; 'source': 0.33; 'extract': 0.33; 'received:google.com': 0.35; 'text': 0.35; 'received:209.85': 0.36; 'possible': 0.36; 'faster': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'client': 0.37; 'received:209': 0.38; 'skip:p 20': 0.38; 'subject:from': 0.39; 'your': 0.60; 'wish': 0.71; '3.4': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=whDFX5VVnHtS6oumppsqPDKSM8NUSKXqNd/qZrO4j9Q=; b=rFtRFqJaoPmHKRKS4FBOtFJfcGJ8n/YT6iGwWfDD5udqUhk694jTOAaSmaQkPqr65I tdxxMZhJoMWyjLfumv0LMB4sS6q8dNYnq98qdMsmYxWYSViQFwIRIp3BzFf/STMqsiAq l6AdiT7HdouWZmVlRKFfGq5/Id6+PfmcHKaUsByxyjBmUt7YiywX6C19pmvHjV68cdiR NdLS3/NxdsjCQVwzlLPiBsiYhpSgdJKTVBPRubSl9uqLb03wuML5v3pYxDYJMlZ1Jx5k jUUaxrueNjxk+jg6VHCwbTVJUbsO1DDMfRuR4GoP1EofZd6bpaybRNjP+itdULz3SMry jYMg==
X-Received by 10.107.138.194 with SMTP id c63mr8262871ioj.103.1449688400510; Wed, 09 Dec 2015 11:13:20 -0800 (PST)
In-Reply-To <CAPv3ojWnWT3jWPk5uauu9Oo+p=zQP2Fawho5NFa9CZAFxP3h4A@mail.gmail.com>
X-Content-Filtered-By Mailman/MimeDel 2.1.20+
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Xref csiph.com comp.lang.python:100208

Show key headers only | 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