Performance on local constants?
John Machin
sjmachin at lexicon.net
Sat Dec 22 15:46:31 EST 2007
On Dec 23, 5:38 am, "Terry Reedy" <tjre... at udel.edu> wrote:
> "Steven D'Aprano" <st... 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 _
>
I see your obfuscatory ante and raise you several dots and
underscores:
class Searcher(object):
def __init__(self, rex):
self.crex = re.compile(rex)
def __call__(self, txt):
return self.crex.search(txt)
Cheers,
John
More information about the Python-list
mailing list