How can i change the __cmp__ function of an instance (not in class)?
Ex:
class foo:
def __init__(self, num):
self.num = num
def cmp(self, other):
return self.num - other.num
# Change __cmp__ function in class works
foo.__cmp__ = cmp
a = foo(1)
b = foo(1)
# returns True
a == b
# Change __cmp__ function in instance that way doesnt work
def cmp2(self, other):
return -1
a.__cmp__ = cmp2
b.__cmp__ = cmp2
# Raise error
a == b
#Traceback (most recent call last):
# File "<stdin>", line 1, in <module>
#TypeError: cmp2() takes exactly 2 arguments (1 given)