Are there something like "Effective Python"?

Aahz aahz at pythoncraft.com
Fri Jun 2 13:29:29 EDT 2006


In article <1149224468.481470.74580 at i39g2000cwa.googlegroups.com>,
Mike Meng <meng.yan at gmail.com> wrote:
>
>    For example, one of my friends read my program and suggest me to
>move the re.compile() out of a for-loop, since the regular pattern is
>fixed, and re.compile() is slow. I want to find more such advice, where
>can I find them?

Actually, that's a good example of a false optimization, unless you're
using a lot of different regexes in the loop or it's an extremely tight
loop, because the re module already caches regexes.  Still, if it's a
constant string, a good programmer would probably hoist it out of the
loop because you should hoist ALL constant assignments out of a loop.
(It's not particularly related to re.compile() in this case.)
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"I saw `cout' being shifted "Hello world" times to the left and stopped
right there."  --Steve Gonedes



More information about the Python-list mailing list