better lambda support in the future?

Fredrik Lundh fredrik at pythonware.com
Fri Dec 17 17:13:48 EST 2004


Steven Bethard wrote:

> I've seen at least one reasonable example of this kind of thing:
>
> http://mail.python.org/pipermail/python-list/2004-October/245432.html

the code he's referring to doesn't seem to use that construct anymore, so
it's not obvious what "dejavu.icontains" etc really is, but assuming they're
strings, the following is a reasonable lambda-free alternative:

class xforms:
    def icontains(self, x, y): return x + " Like '%" + y[1:-1] + "%'"
    def icontainedby(self, x, y):
        # icontainedby body goes here instead of in a separate function
    def istartswith(self, x, y): return x + " Like '" + y[1:-1] + "%'"
    def iendswith(self, x, y): return x + " Like '%" + y[1:-1] + "'"
    def ieq(self, x, y): return x + " = " + y
    def now(self): return "Now()"
    def today(self): return "DateValue(Now())",
    def year(self, x): return "Year(" + x + ")"
    def dispatch(self, tag, *args):
        return getattr(self, tag)(*args)

here's another "reasonable example", btw:

http://groups-beta.google.com/group/comp.lang.python/msg/11462b89a490a6ac

this too could be rewritten to use a class (combined with re.sub and
a callback, most likely).

</F> 






More information about the Python-list mailing list