关于python super的用法疑问
#!/usr/bin/python
# -*- coding: utf-8 -*-
class A(object):
def __init__(self):
print 'A __init__'
pass
class C(object):
def __init__(self):
print 'C __init__'
pass
class B(A,C):
def __init__(self):
print 'B __init__'
super(B, self).__init__()
print 'leave B'
class D(B):
def __init__(self):
print 'D __init__'
super(D, self).__init__()
print 'leave D'
if __name__ == '__main__':
D()
class A(object):
def __init__(self):
print 'A __init__'
super(A, self).__init__()
print 'leave A'
class C(object):
def __init__(self):
print 'C __init__'
super(C, self).__init__()
print 'leave C'
class B(A,C):
def __init__(self):
print 'B __init__'
super(B, self).__init__()
print 'leave B'
class D(B):
def __init__(self):
print 'D __init__'
super(D, self).__init__()
print 'leave D'
if __name__ == '__main__':
D()
class A(object):
def __init__(self):
print 'A __init__'
pass
def test(self):
print 'A.test()'
class C(object):
def __init__(self):
print 'C __init__'
pass
def test(self):
print 'C.test'
class B(A,C):
def __init__(self):
print 'B __init__'
super(B, self).__init__()
print 'leave B'
def test(self):
print 'B.test()'
class D(B):
def __init__(self):
print 'D __init__'
super(D, self).__init__()
print 'leave D'
if __name__ == '__main__':
d = D()
d.test()