I want to implement such case - i have a class, there i have some variable which contains external method, in some situations method can be redefined. It may looks like:
def my_print(self):
print('my print is called')
class example():
some_method = my_print
def __init__(self):
self.some_method()
def test(self):
self.some_method()
So, it works:
a = example()
a.test()
The result looks like:
my print is called (from init)
my print is called (from test)
But in case redefine some_method:
a = example()
a.some_method = my_print
a.test()
It returns a error, which says that i need to give self as argument in the line self.some_method():
TypeError: my_print() missing 1 required positional argument: 'self'
Why does it happen and maybe someone knows trick to solve this problem?