True/False
A. Lloyd Flanagan
alloydflanagan at attbi.com
Fri Apr 25 16:49:46 EDT 2003
and-google at doxdesk.com (Andrew Clover) wrote in message news:<2c60a528.0304240517.25f2fe29 at posting.google.com>...
<snip>
>
> In this case I guess we're looking at something like:
>
> try:
> True
> except NameError:
> exec 'False, True= 0, 1'
> def bool(c):
> if c:
> return True
> return False
>
> Any objections?
Idlefork uses the following:
#"borrowed" from idlefork project, http://idlefork.sourceforge.net/
try:
True
except NameError:
import __builtin__
__builtin__.True = 1
__builtin__.False = 0
from operator import truth
__builtin__.bool = truth
This has the advantage of making True and False look more like
builtins. The only difference is that str(True) is "1" not "True".
Of course, if __builtin__ gets protected, this will die an ugly death.
You could wrap it in "try: ... except Exception: pass", if you were
sufficiently paranoid.
More information about the Python-list
mailing list