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

From Dave Angel <davea@davea.name>
Subject Re: re search through a text Vs line
Date 2014-10-05 16:12 -0400
Organization news.gmane.org
References <loom.20141005T113100-941@post.gmane.org> <m0rbif$bgu$1@ger.gmane.org> <loom.20141005T190455-65@post.gmane.org>
Newsgroups comp.lang.python
Message-ID <mailman.14616.1412539811.18130.python-list@python.org> (permalink)

Show all headers | 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