I wanted to know which class method is being executed in example below. Is there a way to call explicitly using class name? Kindly help.
Example:-
class A():
def test(self, input):
print(input)
class B(A):
def test(self, input):
print(input)
class C(B):
def testing(self):
super().test("foo")
super().test("boo")
run = C()
run.testing()
Output:-
foo
boo
In order to experiment, I tried calling via class name but received error. I understand that, self is for class objects and therefore, should be called via either super() or reference object but my question is how will I know which method is being called during execution and are there any other way to directly call parent method (From Class A) explicitly from Class C?
class A():
def test(self, input):
print(input)
class B(A):
def test(self, input):
print(input)
class C(B):
def testing(self):
A.test("foo")
B.test("boo")
run = C()
run.testing()
Output:-
A.test("foo")
TypeError: test() missing 1 required positional argument: 'input'
A.test(self, "foo")etc. Also don't name your parametersinput, it overrides theinputfunction!superwill call the next method in the method resolution order