A library approach to the ternary operator

Robin Munn rmunn at pobox.com
Mon Mar 24 17:00:49 CET 2003


Jp Calderone <exarkun at intarweb.us> wrote:
>> Both of these then work:
>> 	x = select(condition, lambda:true_result, lambda:false_result)
>> 	x = select(condition, true_result, false_result)
>> 
> 
>   ... until you try to use an actual callable as true_result or
> false_result.
> 
>   In the face of ambiguity, refuse the temptation to guess.
> 
>   Jp

Correct, of course, though it could be solved with documentation: "If
you want a callable as true_result or false_result, you're going to have
to wrap it in a lambda" should do it.

Personally, my preference is for *some* kind of actual operator instead
of a function, but why flagellate a deceased equine?

-- 
Robin Munn <rmunn at pobox.com>
http://www.rmunn.com/
PGP key ID: 0x6AFB6838    50FF 2478 CFFB 081A 8338  54F7 845D ACFD 6AFB 6838




More information about the Python-list mailing list