Hi forum,
-
If a method called with super().c(), a method from sibling classes or parents of sibling classes can be called.
-
If called with self.c(), a method from child class can be called.
-
And the method of its very own self never gets called by default?
Why is that?
Thanks
A B (Parent Classes)
| |
\ /
C (Child Class)
# code:
import os
import sys
import logging
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from libdir import mylog
mylog.config()
class A:
def a(self):
logging.info('') # line 10
super().c()
logging.info('') # line 12
self.c()
def c(self):
logging.info('')
class B:
def b(self):
logging.info('')
# self.c()
def c(self):
logging.info('') # line 24
class C(A, B): # (B, A)
def c(self):
logging.info('') # line 28
c = C()
c.a()
print(C.__mro__)
# log:
$ python3 appdir/main.py
2022-03-13 00:09:45,050 INFO /Users/ljh/Documents/helloPy/appdir/main.py:10:a:
2022-03-13 00:09:45,050 INFO /Users/ljh/Documents/helloPy/appdir/main.py:24:c:
2022-03-13 00:09:45,050 INFO /Users/ljh/Documents/helloPy/appdir/main.py:12:a:
2022-03-13 00:09:45,050 INFO /Users/ljh/Documents/helloPy/appdir/main.py:28:c:
(<class '__main__.C'>, <class '__main__.A'>, <class '__main__.B'>, <class 'object'>)
$