In article <[EMAIL PROTECTED]>, Mike Meng <[EMAIL PROTECTED]> 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 ([EMAIL PROTECTED]) <*> http://www.pythoncraft.com/ "I saw `cout' being shifted "Hello world" times to the left and stopped right there." --Steve Gonedes -- http://mail.python.org/mailman/listinfo/python-list