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

Tim Hochberg tim.hochberg at ieee.org
Thu Feb 13 00:41:42 CET 2003


Tim Hochberg wrote:
> 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.

Sorry my bad, I was reading this with a bad font that made () and {} 
indistinguishable on casual viewing. I thought Bengt was insane and I'm 
sure he thought likewaise as well.

-tim

> 
> 
> 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