PEP 308: I liked the original proposal better

David Glass nospam at nospam.ca
Fri Feb 14 02:22:04 EST 2003


Simon Wittber (Maptek) wrote:
> Greg Ewing wrote:
> 
> 
>>I'd like to put in a plea for re-instatement of the original proposal
>>
>>   x if C else y
>>
>>which I found to be particularly elegant.
> 
> 
> I have to agree. From my point of view this is the most pythonic
> solution.
> 
> Yes, the test is in the middle of the expression. The argument "This is
> not
> the way other languages do ternary expressions" is not a valid argument 
> against its use. Python is about about doing things the Right Way, not
> the
> common accepted way.
> 
> This is what makes Python the great language it is.
> 
> 

Although I am not sure any ternary operator is worth changing the 
language, I too believe the original proposal to be the most Pythonic 
and elegant.

x if C else y

doesn't stick out like

(if C: x else: y)

which, as a special case, requires parentheses. I appreciate the elsif 
capability in the revised PEP, but, the original form chains quite 
nicely to provide equivalent functionality.





More information about the Python-list mailing list