Movatterモバイル変換
[0]ホーム
Boolean Values
D-Mandsh8290 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 wouldneed to be done in each module since a module may be run separatelyfor 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 havetrue = 1false = 0at 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 othercases 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 youthink the words 'true' and 'false' are useless? (natural languagedifferences don't really count because the rest of Python's keywordsand builtin names are in English)-D
More information about the Python-listmailing list
[8]ページ先頭