Regarding the magical "or" operator
Barry A. Warsaw
bwarsaw at cnri.reston.va.us
Tue Aug 17 23:20:53 EDT 1999
>>>>> "GE" == Greg Ewing <greg.ewing at compaq.com> writes:
GE> Personally I think there should be a separate Boolean type,
GE> and it should be an error to test the truth of any other type.
Last time the idea of a boolean type was brought up, I think we zeroed
<wink> in on the attached Python prototype. I'm not sure I like the
second half of your proposal; it works okay I s'pose in Java, but
doesn't seem right in Python.
-Barry
-------------------- snip snip --------------------
class Bool:
def __init__(self, flag=0):
self.__flag = not not flag
def __str__(self):
return self.__flag and 'true' or 'false'
def __repr__(self):
return self.__str__()
def __nonzero__(self):
return self.__flag == 1
def __cmp__(self, other):
if (self.__flag and other) or (not self.__flag and not other):
return 0
else:
return 1
def __rcmp__(self, other):
return -self.__cmp__(other)
true = Bool(1)
false = Bool()
More information about the Python-list
mailing list