"!=" is bad form. Re: sorry....never mind

Tim Hochberg tim.hochberg at ieee.org
Fri Mar 9 15:11:12 EST 2001


"Peter Schneider-Kamp" <peter at schneider-kamp.de> wrote in message
[SNIP]
> Well, Python *does* define an ordering of a and b, no matter what
> a and b may be. E.g.:
>
> >>> 1 > (1,2)
> 0
> >>> 1 < (1,2)
> 1
[SNIP]

This used to be true, but for better or for worse this hasn't been true for
a while. It's true for most builtin objects still, but for instance:

>>> class Uncomparable:
 def __cmp__(self, other):
  raise RuntimeError("I can't be compared")

>>> u = Uncomparable()
>>> u < 5
Traceback (innermost last):
  File "<pyshell#10>", line 1, in ?
    u < 5
  File "<pyshell#8>", line 3, in __cmp__
    raise RuntimeError("I can't be compared")
RuntimeError: I can't be compared

The guarantee of all types being ordered is likely to erode further with the
advent of rich comparisons in Python 2.1 (PEP 207).

-tim






More information about the Python-list mailing list