Numeric comparison anomaly
Paul Rubin
http
Thu Feb 20 17:22:19 EST 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:
if some_test(sequence[n]):
break
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
mailing list