Performance on local constants?

Terry Reedy tjreedy at udel.edu
Sat Dec 22 13:38:28 EST 2007


"Steven D'Aprano" <steve at REMOVE-THIS-cybersource.com.au> wrote in message 
news:13mq041tef27vad at corp.supernews.com...
| >>> def spam2(x, s=re.compile('nobody expects the Spanish 
Inquisition!')):
| ...     return s.search(x)
|
| I suspect that this will be not only the fastest solution, but also the
| most flexible.

'Most flexible' in a different way is

def searcher(rex):
    crex = re.compile(rex)
    def _(txt):
        return crex.search(txt)
    return _

One can then create and keep around multiple searchers based on different 
patterns, to be used as needed.

tjr






More information about the Python-list mailing list