我有以下课程:
class c0(object):
def post_pred(self, ins):
print("this is post_pred in c0")
class c1(c0):
def __init__(self):
print("this is class c1")
def predict(self, ins):
print("this is predict in c1")
selfz.post_pred(0)
def post_pred(self,ins):
print("this is post_pred in c1")
class c2(c1):
def __init__(self):
super().__init__()
print("this is class c2")
def predict(self, ins):
super().predict(0)
print("this is predict in c2")
self.post_pred(0)
def post_pred(self, ins):
print("this is post_pred in c2")
if __name__ == '__main__':
sss = c2()
sss.predict(2)
我想看到的是运行此脚本后,看到以下输出:
this is class c1
this is class c2
this is predict in c1
this is post_pred in c1
this is predict in c2
this is post_pred in c2
但是我看到了:
this is class c1
this is class c2
this is predict in c1
this is post_pred in c2
this is predict in c2
this is post_pred in c2
似乎继承没有扩展到post_pred
函数。我只是想知道实现我的目标的正确方法。