1.子类调用父类:
super(subClass,subObject).fatherMethod
super(testAdmin, test).doSomethings()
2.父类中调用子类方法:
child_method = getattr(self, 'doSomethings') # 获取子类的out()方法
child_method()
3.example:
父类
class IAdmin:
adminCount = 0
def __init__(self):
pass
def doSomethings(self):
child_method = getattr(self, 'doSomethings') # 获取子类的out()方法
child_method()
def doAdmin(self):
print("this is father IAdmin Method")
self.doSomethings()
子类
from Interface.common.IAdmin import IAdmin
class testAdmin(IAdmin):
def __init__(self):
pass
def doSomethings(self):
print("this is subClass Method")
test = testAdmin()
super(testAdmin, test).doAdmin()
结果:
this is father IAdmin Method
this is subClass Method