What's the purpose the hook method showing in a class definition?
jfong at ms4.hinet.net
jfong at ms4.hinet.net
Sat Oct 19 07:11:21 EDT 2019
For the two examples below:
(1)
>>> class A:
... def foo(self):
... self.goo()
...
>>> class B(A):
... def goo(self):
... print(1)
...
(2)
>>> class A:
... def foo(self):
... self.goo()
... def goo(self): pass
...
>>> class B(A):
... def goo(self):
... print(1)
...
Both can get the same result:
>>> b = B()
>>> b.foo()
1
>>>
What's the benefit of having the hook method goo() in class A in example 2?
--Jach
More information about the Python-list
mailing list