Numeric comparison anomaly
Thu Feb 20 23:22:19 CET 2003
"Piet van Oostrum" <piet at cs.uu.nl> writes:
> Yes, of course, but I mean that I consider this an incorrect
> definition of __cmp__.
> class A:
> def __cmp__(self, other):
> return self is not other
> would be better.
Hmm, I guess that's an improvement but still leaves an anomaly:
inf1 = A()
inf2 = A()
print (inf1 == inf2)
would then print 0.
Anyway I didn't really need a general infinity. I just wanted a simple
way to write a loop with an optional maximum count:
n = 0
while n <= limit:
Letting limit be infinite was the simplest way of expressing that I
sometimes didn't want to have a limit.
More information about the Python-list