python调用基类方法
-
测试代码
class P(object): def __init__(self): print "calling P's constructor" class C(P): def __init__(self): P.__init__(self) # 硬编码显式调用 print "calling C's constructor" class D(C): def __init__(self): super(D,self).__init__() # 使用super调用 print "calling D's constructor" print "---------p()-----------" p=P() print "---------c()-P()-------" c=C() print '---------d()-C()-------' d=D()
-
输出
---------p()----------- calling P's constructor ---------c()-P()------- calling P's constructor calling C's constructor ---------d()-C()------- calling P's constructor calling C's constructor calling D's constructor