[Chicago] Ode to <>

Ian Bicking ianb at colorstudy.com
Fri Sep 1 17:22:19 CEST 2006

Brian Ray wrote:
> class A:
>     def __init__(self,title):
>        self.title = title
>     def __cmp__(self,rhs):
>        return rhs.title == self.title

You got __cmp__ wrong -- you probably meant to do __eq__; __cmp__ is a 
-1/0/1 sorting comparison.  So 0 means equal (-1 means less-than, 1 
means more-than).

You should also do something like "if isinstance(rhs, self.__class__)", 
since "A() == 'foo'" is a valid expression that shouldn't raise an 

Ian Bicking | ianb at colorstudy.com | http://blog.ianbicking.org

More information about the Chicago mailing list