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


Groups > comp.lang.python > #78722

Re: re search through a text Vs line

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!bcyclone01.am1.xlned.com!bcyclone01.am1.xlned.com!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'programmer': 0.03; 'encoding': 0.05; 'subject:text': 0.05; 'modified': 0.07; 'exception.': 0.09; 'processing,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'spaces': 0.09; 'wrote': 0.14; 'cryptic': 0.16; 'efficiency.': 0.16; 'indent': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'scope,': 0.16; 'subject:search': 0.16; 'memory': 0.22; 'separate': 0.22; 'replace': 0.24; 'rid': 0.24; 'unicode': 0.24; 'file.': 0.24; 'header:X-Complaints-To:1': 0.27; 'leave': 0.29; 'statement': 0.30; 'code': 0.31; 'usually': 0.31; 'comment': 0.34; 'could': 0.34; 'add': 0.35; 'there': 0.35; 'disk': 0.36; 'next': 0.36; 'performance': 0.37; 'skip:o 20': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'either': 0.39; 'received:org': 0.40; 'how': 0.40; 'read': 0.60; 'matter': 0.61; 'first': 0.61; 'pick': 0.64; 'more': 0.64; 'finally': 0.65; 'gain': 0.79; 'commands.': 0.84; 'received:myvzw.com': 0.84; 'mean.': 0.91
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Dave Angel <davea@davea.name>
Subject Re: re search through a text Vs line
Date Sun, 5 Oct 2014 16:12:52 -0400 (EDT)
Organization news.gmane.org
References <loom.20141005T113100-941@post.gmane.org> <m0rbif$bgu$1@ger.gmane.org> <loom.20141005T190455-65@post.gmane.org>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host 231.sub-70-208-145.myvzw.com
X-Newsreader PiaoHong.Usenet.Client.VIP:1.62
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
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>
Newsgroups comp.lang.python
Message-ID <mailman.14616.1412539811.18130.python-list@python.org> (permalink)
Lines 44
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1412539811 news.xs4all.nl 2931 [2001:888:2000:d::a6]:38525
X-Complaints-To abuse@xs4all.nl
X-Received-Bytes 3986
X-Received-Body-CRC 428274539
Xref csiph.com comp.lang.python:78722

Show key headers only | View raw


Shiva <shivaji_tn@yahoo.com.dmarc.invalid> Wrote in message:
> OK,
> Hi Dave,
> 
> I modified it as below and it works....(If there is a way to make this more
> efficient please let me know)
> 

Deends on what you mean by efficiency. 

The big memory efficiency gain was when you got rid of either the
 read or readlines.

Performance is pretty irrelevant,  since disk I/O, unicode
 processing,  and terminal processing are likely to
 dominate.

Programmer efficiency is usually more important than either of those.

First thing is to pick better names, and/or comment what the
 cryptic names mean. And avoid any names that look like
 numbers.

Next are to add in the shebang and encoding commands.

You could replace
   fileextract = open(fullfilename,'r')

With
    with  open(fullfilename,'r') as fileextract:

And indent the code that uses the file. That way it's clearer, you
 don't need the separate close, and it will be closed no matter
 how you leave that scope,  whether a return statement or
 exception.

Finally you could indent by 4 spaces instead of 1.

HTH


-- 
DaveA

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


Thread

Re: re search through a text Vs line Dave Angel <davea@davea.name> - 2014-10-05 16:12 -0400
  Re: re search through a text Vs line wxjmfauth@gmail.com - 2014-10-06 00:46 -0700

csiph-web