Numeric comparison anomaly

Piet van Oostrum piet at cs.uu.nl
Thu Feb 20 05:55:34 EST 2003


>>>>> Gerrit Holl <gerrit at nl.linux.org> (GH) schreef:

GH> You can use the __cmp__ overloader:

GH>  21 >>> class A:
GH>  21 ...  def __cmp__(self, other):
GH>  21 ...   return 1
GH>  21 ...
GH>  22 >>> A() > 5
GH> True
GH>  23 >>> A() < 9
GH> False
GH>  24 >>> A() >= 3
GH> True

>>> inf = A()
>>> inf > inf
True
>>> inf == inf
False
>>> 

-- 
Piet van Oostrum <piet at cs.uu.nl>
URL: http://www.cs.uu.nl/~piet [PGP]
Private email: P.van.Oostrum at hccnet.nl




More information about the Python-list mailing list