[Tutor] toggle idiom?

Jeff Shannon jeff@ccvcorp.com
Thu, 09 May 2002 09:44:21 -0700


dman wrote:

>
> | Yes, unlike the a = not a thing the behaviour of the "psuedo-ternary
> | operator" is not specified anywhere.  I'm not sure I agree about this
> | failing in the future, but ideally that's something I'd rather not have
> | to find out.  :-)
>
> PEP 285 says that all the boolean operations will be changed to return
> either True or False.  If the expression returns True, and True !=
> <object I wanted>, then the hack doesn't work anymore.  It only works
> now because python doesn't "normalize" the result to a boolean object.

In discussions on c.l.py, the PythonLabs folks did specifically say that the
behavior of and/or won't change -- they will still return the full result, and
not normalize to boolean.  I believe that the main reason for this *is*
backwards compatibility, because the and/or pseudo-trinary thing has been in
use for a long time.  (Personally, I would never use it, as it seems unclear
at best, and downright obfuscatory at worst, but that's me.)

Jeff Shannon
Technician/Programmer
Credit International