dynamic functions
holger krekel
pyth at devel.trillke.net
Mon May 13 20:46:49 EDT 2002
Uwe Mayer wrote:
> I want to concatenate boolean functions, i.e. lambda x: x < 10; during
> runtime with "and" and "or".
> However something like:
>
> d = lambda x: x < 10
> d = lambda x: d(x) and (x %2 == 0)
note that the name 'd' in 'd(x)' is *not* resolved at definition time.
this happens at calling time. But at calling time of 'd' you call
'd' again and again ...
> won't work and will end up in an infinite recursion (as far as I can
> figure out).
> How do you do something like that in python?
you don't use confusing names:
func1 = lambda x: x < 10
func2 = lambda x: func1(x) and (x%2==0)
regards,
holger
More information about the Python-list
mailing list