Boilerplate in rich comparison methods

Steven D'Aprano steve at REMOVE.THIS.cybersource.com.au
Sat Jan 13 14:09:09 EST 2007


On Fri, 12 Jan 2007 23:28:06 -0800, Paul Rubin wrote:

> Steven D'Aprano <steve at REMOVE.THIS.cybersource.com.au> writes:
>> class Parrot:
>>     def __eq__(self, other):
>>         return self.plumage() == other.plumage()
>>     def __ne__(self, other):
>>         return self.plumage() != other.plumage()
>>     def __lt__(self, other):
>>         return self.plumage() < other.plumage()

[snip more boilerplate code]

> If it's that uniform I think you can just use __cmp__:

Good point -- I had somehow picked up the mistaken idea that __cmp__ was
depreciated in favour of rich comparisons.


-- 
Steven.




More information about the Python-list mailing list