[Python-3000] Please re-add __cmp__ to python 3000

Greg Ewing greg.ewing at canterbury.ac.nz
Wed Oct 31 05:46:16 CET 2007


Steven Bethard wrote:
>     class C(object):
>         def __cmp__(self, other):
>             if self.foo < other.foo:
>                 return -1
>             elif self.foo < other.foo:
>                 return 1
>             else:
>                 return 0

With __cmp__, in cases like that you can punt the whole
thing off to the subsidiary object, e.g.

   def __cmp__(self, other):
     return cmp(self.foo, other.foo)

--
Greg


More information about the Python-3000 mailing list