How does Python's super() work with multiple inheritance?

后端 未结 16 2196
孤街浪徒
孤街浪徒 2020-11-21 05:19

I\'m pretty much new in Python object oriented programming and I have trouble understanding the super() function (new style classes) especially when it comes to

16条回答
  •  不思量自难忘°
    2020-11-21 05:48

    I understand this doesn't directly answer the super() question, but I feel it's relevant enough to share.

    There is also a way to directly call each inherited class:

    
    class First(object):
        def __init__(self):
            print '1'
    
    class Second(object):
        def __init__(self):
            print '2'
    
    class Third(First, Second):
        def __init__(self):
            Second.__init__(self)
    
    

    Just note that if you do it this way, you'll have to call each manually as I'm pretty sure First's __init__() won't be called.

提交回复
热议问题