Boolean Values

D-Man dsh8290 at rit.edu
Thu Apr 5 13:28:01 EDT 2001


On Tue, Apr 03, 2001 at 09:59:32PM +0200, Moshe Zadka wrote:
| For all those crying for boolean values, here's a simple module
| that will hopefully solve all your needs:
| 
...
| import __builtin__
| __builtin__.true = _true()
| __builtin__.false = _false()
| __builtin__.dunno = _dunno()


Err,

>>> __builtins__.true = _true()
Traceback (innermost last):
  File "<console>", line 1, in ?
NameError: __builtins__
>>>

It didn't work.  The first two lines of output are :

Jython 2.0 on java1.3.0 (JIT: null)
Type "copyright", "credits" or "license" for more information.


Jython doesn't allow such trickery like CPython does (I didn't  del
__builtins__ or something stupid like that).  In any case, this would
need to be done in each module since a module may be run separately
for unittests.  The other alternative would be to add it to site.py,
but that is horrible for installation on a user's system.

As it is, I have

true  = 1
false = 0

at the beginning of each file.  It doesn't do everything I want it to
(like  some_val == true  working properly) but it works for all other
cases where it is actually used.

| To the people who don't know me yet: when I say "it can be done in
| Python in 20 lines, here's the code", I usually mean "I don't think
| it has any merit. Nobody's done it not because it's hard, but because
| it's useless" ;-)

I know it would be a quite trivial implementation, but why do you
think the words 'true' and 'false' are useless?  (natural language
differences don't really count because the rest of Python's keywords
and builtin names are in English)

-D





More information about the Python-list mailing list