PEP-308 a "simplicity-first" alternative
Bengt Richter
bokr at oz.net
Wed Feb 12 21:31:46 EST 2003
On Wed, 12 Feb 2003 17:50:42 -0800, Erik Max Francis <max at alcyone.com> wrote:
>Bengt Richter wrote:
>
>> My fix is
>> x and {y} or z
>>
>> meaning y is treated as True in logical expression context, but
>> retains its value for purposes of the expression value.
>
>And, as I've pointed out through these threads, I think that cure is
>worse than the disease.
>
"That cure" hasn't been presented before AFAIK, so how can you have pointed
out anything about it before?
Unless you are looking at it through special-ternary-syntax-colored goggles,
and aren't seeing what it actually does.
It is _not_ a ternary syntax. {x} is an expression all by itself, just as [x] is,
except that all it does is guarantee that {x} will be seen as true in any logical
expression context.
It just happens to be usable to fix the hole in the old ternary idiom.
IMO it's a good substitute for using a list to guarantee
a true term, as in (x and [y] or [z])[0]
Of course, if you intensely dislike the old x and y or z idiom, making it
bullet proof will not particularly please you ;-)
OTOH, others have pointed out that the old idiom has seen considerable use
in the libraries, so maybe a 2-character bulletproofing is not such a bad idea?
Does
x and {y} or {z}
read better as making the two choices easily identifiable?
({} is optional on the second term).
Give it another thought ;-)
Regards,
Bengt Richter
More information about the Python-list
mailing list