PEP 308: Alternative conditional operator forms -- Corner Case solved

Tim Hochberg tim.hochberg at ieee.org
Wed Feb 12 17:05:02 EST 2003


Bengt Richter wrote:
> On Wed, 12 Feb 2003 09:27:47 -0800 (PST), Dave Brueck <dave at pythonapocrypha.com> wrote:
> 
> 
>>On Wed, 12 Feb 2003, Michele Simionato wrote:
>>
>>
>>>I must say that even if initially I said "if C: x else: y" is ugly but
>>>better than nothing, in the last few days the arguments of Samuele and
>>>others finally convinced me that "nothing" is better than such a
>>>confusion between expressions and statement. It seems to me absolutely
>>>contrary to the Python design philosophy.
>>
>>Just bear in mind that "do nothing" also means "stay with the current
>>idiom that in some cases doesn't work" (yeah, you can hear my bias in that
>>statement ;-) ).
>>
> 
> The current idiom can be made to work if we can mark the troublesome term
> so that it will be treated as True in the logical expression, but will retain
> its value. I am proposing {x} to mean treat x as true that way.
> Hence
> 
>     c and {x} or y
> 
> is guaranteed to work as a ternary, and you can optionally write
> 
>     c and {x} or {y}
> 
> for stylistic symmetry if you like.


This seems like it would cause a problem in standard condionals:

if (c == b) and (x == y):
     do_something()

Would change meaning in an unfortunate way, would it not?

-tim





More information about the Python-list mailing list