PEP-308 a "simplicity-first" alternative

Bengt Richter bokr at oz.net
Wed Feb 12 16:13:58 EST 2003


On Wed, 12 Feb 2003 17:42:19 +1300, Paul Foley <see at below.invalid> wrote:

>On Tue, 11 Feb 2003 20:32:25 +0100, holger krekel wrote:
>
>> I am still wondering if there is a simple way to fix the current 
>> ternary op "x and y or z".  Everybody knows by now that 
>> this "fails" if y is a false value.  Otherwise
>> it works ok and is used in today's code everywhere. 
>
>> Inspired by "do the simplest thing that can possibly work"
>> i now think that 
>
>>         x and y else z
>
>Yuck.  -INF
>
>That's even worse than Bengt's scary a -> b >< c -> d >!< e -> f -> g
>thing.
Ok, but I was just doing what_you_like_best[1:-1].replace(';','><')
and adding '>!<' for Holger's exception catching ;-)
>
>x then y else z is good.  (But I like [x -> y; 1 -> z] better)
>
My latest-ang-greatest is just to use the old expression with a minimal markup:

    x and {y} or z

where {y} means treat y as True in logical expression context, but don't change
the value. Stylistically,

    x and {y} or {z}

is optional.

Regards,
Bengt Richter




More information about the Python-list mailing list