Let's say I want to override a type function __int__in a Python class so that I can do something like this.
class A(object):
def __init__(self):
self.__int__ = lambda: 1
a = A()
print int(a)
I expect "1" to be displayed here instead of causing this error message
Argument TypeError: int () must be a string or a number, not "A"
When __int__instead it becomes a method embedded in a class, it works as expected. What for? (This problem exists for any of the double underscore functions)
source
share