Python 2.x has two ways to overload comparison operators, __cmp__ or the \"rich comparison operators\" such as __lt__. The rich comparison overloads are said to be
(Edited 6/17/17 to take comments into account.)
I tried out the comparable mixin answer above. I ran into trouble with "None". Here is a modified version that handles equality comparisons with "None". (I saw no reason to bother with inequality comparisons with None as lacking semantics):
class ComparableMixin(object):
def __eq__(self, other):
if not isinstance(other, type(self)):
return NotImplemented
else:
return not self