Python paradigms
Remco Gerlich
scarblac-spamtrap at pino.selwerd.nl
Sun Apr 16 13:50:53 EDT 2000
Andrew Dalke wrote in comp.lang.python:
> Aahz Maruch wrote:
> >def expression_if( test, true, false ):
> > if test: return true
> > else: return false
> >
> >x = expression_if( a is not None,
> > a[i].weeble, 0) + expression_if( b is not None, b[i].wombat, 0)
>
>
> Suppose a is None. The a[i].weeble will give an exception.
Pass functions?
def exp_if(test, true, false):
if test: return true()
else: return false()
x = exp_if(a is not None, lambda a=a,i=i: a[i].weeble, lambda: 0)
Getting silly, though :)
--
Remco Gerlich, scarblac at pino.selwerd.nl
8:46pm up 41 days, 8:07, 6 users, load average: 1.19, 1.08, 1.07
More information about the Python-list
mailing list