"John Machin" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
| On Dec 23, 5:38 am, "Terry Reedy" <[EMAIL PROTECTED]> wrote:
| > '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:

I will presume you are merely joking, but for the benefit of any beginning 
programmers reading this, the closure above is a standard functional idiom 
for partial evaluation of a function (in this this, re.search(crex,txt))

| class Searcher(object):
|    def __init__(self, rex):
|        self.crex = re.compile(rex)
|    def __call__(self, txt):
|        return self.crex.search(txt)

while this is, the equivalent OO version.  Intermdiate Python programmers 
should know both.

tjr



-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to