True/False
Skip Montanaro
skip at pobox.com
Tue Apr 22 14:42:34 EDT 2003
Ian> True, False = 1==1, 0==1
Why not
try:
True
except NameError:
True, False = 1==1, 0==1
? Should work anywhere without complaints.
Ian> Is there any reason why reassigning True and False will be a
Ian> problem in the future?
The builtins may get "tightened up" in the future. This particular idiom
probably won't be affected, but you may not be able to (easily) shadow a
builtin in another module's global namespace, e.g.:
import a
a.True, a.False = 1==1, 0==1
might not be possible. The idea here is to allow the byte compiler to know
all the possible builtin shadowing that goes on in a module by examining
just the module itself. This, in turn, would allow access to builtins (and
globals to some extent I think) to be optimized.
Ian> Should I tell people who are putting in version tests that it isn't
Ian> necessary?
Testing against particular versions is generally not a good idea. I'd test
against the presence of the object in question instead.
Skip
More information about the Python-list
mailing list