True/False
Erik Max Francis
max at alcyone.com
Tue Apr 22 17:17:39 EDT 2003
Ian Bicking wrote:
> I've been using True and False for a while now, and I put this at the
> top of my files:
>
> True, False = 1==1, 0==1
>
> But people seem concerned about this with Python 2.3. I don't think
> they should be concerned, while I'm reassigning True and False, I'm
> not
> redefining them.
There was talk about instituting warnings for rebinding True and False
to any value, like is currently done for None:
Python 2.3a2 (#1, Feb 19 2003, 20:06:49)
[GCC egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> None = 'asdf'
<stdin>:1: SyntaxWarning: assignment to None
If done, then a blanket statement like yours above would start
generating warnings eventually; they'd be harmless warnings, but they'd
be unnerving and annoying.
> import sys
> if sys.version_info < (2, 3):
> True, False = 1==1, 0==1
This would be okay (although the untyped version of the True and False
builtins were introduced in 2.2, not 2.3). The solution I've adopted
is:
try:
True
except NameError:
True, False = 1, 0
--
Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
__ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/ \ There are defeats more triumphant than victories.
\__/ Montaigne
Discord / http://www.alcyone.com/pyos/discord/
Convert dates from Gregorian to Discordian.
More information about the Python-list
mailing list