如果Child多重继承(Parent_1,Parent_2,Parent_3),其super函数
super(Child, self).__init__()
则会执行继承的最左侧的父类:Parent_1.__init__()
但是如果Parent_2是QObject或QObject的子孙类,
在Child的中__init__()中执行QObject.__init__(self)
则会使Parent_3.__init__(self)被执行
原因不明。。。。。。。。。
例子哈:
from PyQt5.QtCore import QObject
class Parent_1:
def __init__(self):
print('Parent_1.__init__') class Parent_2(Parent_1):
def __init__(self):
super(Parent_2, self).__init__()
print('Parent_2.__init__') class Parent_3:
def __init__(self):
print('Parent_3.__init__') class Child_2( QObject , Parent_2,Parent_3):
def __init__(self):
#QObject.__init__(self)
super(QObject, self).__init__()
#super(Child_2, self).__init__() if __name__ == '__main__': import sys
from PyQt5.QtWidgets import QApplication
app = QApplication(sys.argv)
##################################################### print('---------------------------')
child_2 = Child_2()
#####################################################
sys.exit(app.exec_())
输出结果为:
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQAAAABYCAIAAACVur4fAAACwklEQVR4nO3c0XmrIACGYeZygy7iPE7jtXswTHqRGEFBtGgB/++9OylJ7HP4qkaJmaZpmqZXgh060w02Nex57NAZY4zmL98iO3TG9OPh8eZYAMAzEQCkEQCkEQCkEQCkEQCkeQHYodv/BCl/AFCVTQBm72Pv/AFAVbaHQGNvvoKzOH8AUIvoOQAdQEHqJPgzi+PH9TkD3ES+kfAgD+4/eCn2AJDGOQCk8SkQpHEdANK4EgxpBABpBABpBABpBABpBABpBABpBABpwgEkv+tI9suQlDgBLLcxvN1/RffsDCs4I4nhoVYBLP/HY39/A8dnVfF7jAjgoaIBuP/09w3zmPeAwbvd37kRdI7HG7b+wbnbRq+dhd9Xi23h8nbnNxWNOBSAa/nuxfescHYSY7+e9nY7LDzomBsDCG2h+3bsAR4qFoAdusifuu8Nn4lgxj45rKIAQltIAALiJ8He8X/oZ4F5s7I7vbavkEQAuFr8EGgx9u7OYG8PEDppJgBU7EAA/uP+OYA33j28f73s0CWPlPxnJAXf8c9npacCOLupaMSRPYD34U7X9+E9wHrgPF92TxWOfrwZuUbxjwGU/yQWdxC+EgzUFID/FTCRk/HzT//5yXrZ4u+Fe9UTAFAAAUAaAUAaAUAaAUAaAUCacACsCEMrK8K8TSsyJ4nhoZpYETbfVjQ/p8CVJQJ4qKZWhK23Kw8rwtDYirDNC2RhRRgaWxF27QEQ6wHQ2Iowf2VOLgJAQyvCrj/5JQC0siIs9qefFWHI1MSKsO3995/RrAhDJuErwUBNAbAiDAXUEwBQAAFAGgFAGgFAGgFAGgFAGgFAGgFAGgFAGgFAGgFAGgFAGgFAGgFAGgFAGgFAGgFAGgFAGgFAGgFAGgFAGgFAGgFAGgFAGgFAGgFAGgFAGgFAGgFAGgFAGgFAGgFAGgFAGgFA2i+0gYZWPqixfgAAAABJRU5ErkJggg==" alt="" />