Python的super()如何与多重继承一块儿使用? - How does Python's super() work with multiple inheritance?

问题:

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 multiple inheritance. 我在面向对象的Python编程中很是陌生,尤为是在涉及多重继承时,我很难理解super()函数(新样式类)。 编程

For example if you have something like: 例如,若是您有相似的东西: 函数

class First(object):
    def __init__(self):
        print "first"

class Second(object):
    def __init__(self):
        print "second"

class Third(First, Second):
    def __init__(self):
        super(Third, self).__init__()
        print "that's it"

What I don't get is: will the Third() class inherit both constructor methods? 我不明白的是: Third()类会继承两个构造函数方法吗? If yes, then which one will be run with super() and why? 若是是,那么哪一个将与super()一块儿运行,为何? spa

And what if you want to run the other one? 若是要运行另外一台呢? I know it has something to do with Python method resolution order ( MRO ). 我知道这与Python方法解析顺序( MRO )有关。 .net


解决方案:

参考一: https://stackoom.com/question/Dkal/Python的super-如何与多重继承一块儿使用
参考二: https://oldbug.net/q/Dkal/How-does-Python-s-super-work-with-multiple-inheritance
相关文章
相关标签/搜索