Let's say I want to override a function like __int__
in a Python class so that I may do something like this.
class A(object):
def __init__(self):
self.__int__ = lambda: 1
a = A()
print int(a)
I expect that it would output "1" here instead of produce this error message
TypeError: int() argument must be a string or a number, not 'A'
When __int__
instead becomes a method built into the class it works as expected. Why? (This problem exists with any of the double underscore functions also)