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