Movatterモバイル変換
[0]ホーム
Boolean Values
Moshe Zadkamoshez at zadka.site.co.il
Tue Apr 3 15:59:32 EDT 2001
For all those crying for boolean values, here's a simple modulethat will hopefully solve all your needs:=========== Boolean.py ==============# Boolean.pyclass _true:def __nonzero__(self):return 1class _false:def __nonzero__(self):return 0class _dunno:def __nonzero__(self):raise ValueError("I dunno")import __builtin____builtin__.true = _true()__builtin__.false = _false()__builtin__.dunno = _dunno()=========== /Boolean.py ==============Use as follows:Python 2.1b2 (#1, Mar 24 2001, 09:04:30)[GCC 2.95.3 20010219 (prerelease)] on linux2Type "copyright", "credits" or "license" for more information.>>> import Boolean>>> if true:... print "yay!"...yay!>>> if false:... print "wrong"...>>> if dunno:... print "huh?"...Traceback (most recent call last): File "<stdin>", line 1, in ? File "Boolean.py", line 12, in __nonzero__ raise ValueError("I dunno")ValueError: I dunnoTo the people who don't know me yet: when I say "it can be done inPython in 20 lines, here's the code", I usually mean "I don't thinkit has any merit. Nobody's done it not because it's hard, but becauseit's useless" ;-)I'm only clarifying lest someone will actually try to get this integratedinto Python ;-)-- "I'll be ex-DPL soon anyway so I'm |LUKE: Is Perl better than Python?looking for someplace else to grab power."|YODA: No...no... no. Quicker, -- Wichert Akkerman (on debian-private)| easier, more seductive.For public key, fingermoshez at debian.org |http://www.{python,debian,gnu}.org
More information about the Python-listmailing list
[8]ページ先頭