something like "if" that returns a value?

Paul Rudin paul.rudin at ntlworld.com
Mon Nov 11 16:20:56 EST 2002


>>>>> "holger" == holger krekel <pyth at devel.trillke.net> writes:


 holger> if you are doing this often of course you could write a
 holger> helper...  but

But what kind of helper? Writing a function doesn't get round the
unnecessary evaluation problem. (Arguably it also doesn't entirely help
with the obfuscation problem either.)


 >> Personally I'd prefer to be able to write something like:
 >> 
 >> def foo(x,y,....): return func1(x,y,..) + if some_test:
 >> func2(x,y...)  else: func3(x,y..)

 holger> def foo(*args): return func1(*args) + (func2,func3)[not
 holger> some_test](*args)

Yah - I didn't mean to imply that the arity and order of the arguments
was necessarily always the same. But still, in some cases this will be
a useful thing. (Although again there's still the obfuscation issue).




More information about the Python-list mailing list