class First(object):
def __init__(self, a1, *args, **kwargs):
# super(First, self).__init__(*args, **kwargs)
print("First: a1:{0}".format(a1))
print("First: args: ", args)
print("First: kwargs: ", kwargs)
class Second(First):
def __init__(self, a2, b2, *args, **kwargs):
super(Second, self).__init__(*args, **kwargs)
print("Second: a2:{0} b2:{1}".format(a2, b2))
print("Second: args: ", args)
print("Second: kwargs: ", kwargs)
class Third(First):
def __init__(self, a3, b3, c3, *args, **kwargs):
super(Third, self).__init__(*args, **kwargs)
print("Third: a3:{0} b3:{1} c3:{2}".format(a3, b3, c3))
print("Third: args: ", args)
print("Third: kwargs: ", kwargs)
class Fourth(Second, Third):
def __init__(self, *args, **kwargs):
super(Fourth, self).__init__(*args, **kwargs)
print("Fourth: args: ", args)
print("Fourth: kwargs: ", kwargs)
print("Fourth: that's it")
In [66]: Fourth.__mro__
Out[66]: (__main__.Fourth, __main__.Second, __main__.Third, __main__.First, object)
In [76]: Fourth(101, 201, 202, 301, 302, 303)
First: a1:303
First: args: ()
First: kwargs: {}
Third: a3:202 b3:301 c3:302
Third: args: (303,)
Third: kwargs: {}
Second: a2:101 b2:201
Second: args: (202, 301, 302, 303)
Second: kwargs: {}
Fourth: args: (101, 201, 202, 301, 302, 303)
Fourth: kwargs: {}
Fourth: that's it
Out[76]: <__main__.Fourth at 0x6a7d550>
In [77]: Fourth(101, 201, 202, 301, 302, 303, 401, 402, 403, 404, m1=501, m2=502)
First: a1:303
First: args: (401, 402, 403, 404)
First: kwargs: {'m1': 501, 'm2': 502}
Third: a3:202 b3:301 c3:302
Third: args: (303, 401, 402, 403, 404)
Third: kwargs: {'m1': 501, 'm2': 502}
Second: a2:101 b2:201
Second: args: (202, 301, 302, 303, 401, 402, 403, 404)
Second: kwargs: {'m1': 501, 'm2': 502}
Fourth: args: (101, 201, 202, 301, 302, 303, 401, 402, 403, 404)
Fourth: kwargs: {'m1': 501, 'm2': 502}
Fourth: that's it
Out[77]: <__main__.Fourth at 0x6a7dd68>
In [79]: Fourth(a2=101, c=10, d=100, a1=201, b2=202, a3=301, b3=302, c3=303, x=200)
First: a1:201
First: args: ()
First: kwargs: {'c': 10, 'd': 100, 'x': 200}
Third: a3:301 b3:302 c3:303
Third: args: ()
Third: kwargs: {'c': 10, 'd': 100, 'a1': 201, 'x': 200}
Second: a2:101 b2:202
Second: args: ()
Second: kwargs: {'c': 10, 'd': 100, 'a1': 201, 'a3': 301, 'b3': 302, 'c3': 303, 'x': 200}
Fourth: args: ()
Fourth: kwargs: {'a2': 101, 'c': 10, 'd': 100, 'a1': 201, 'b2': 202, 'a3': 301, 'b3': 302, 'c3': 303, 'x': 200}
Fourth: that's it
Out[79]: <__main__.Fourth at 0x69909b0>
According to this article about Method Resolution Order
Deep Thoughts by Raymond Hettinger