1

Given below is a multiple inheritence snippet in python. In this while using super for childMyClass we hit MyCass2 in the code flow. Please explain why the code flow includes MyClass2? According to my knowledge python evaluates the classes left to right, so ChildMyClass should call MyClass1 which in turn call MyClass and return from there. Where is MyClass2 coming in picture.

class MyClass(object):
    def __init__(self, data1, data2):
        self.data1=data1
        self.data2=data2
        print "MyClass"
    def f(self):
        print "Hello"

class MyClass1(MyClass):
    def __init__(self, data):
       super(MyClass1, self).__init__(data, 1)
       print "MyClass1"
    def f1(self):
       print "Hello1"

class MyClass2(MyClass):
    def __init__(self, data1, data2):
        super(MyClass2, self).__init__(data1, data2)
        print "MyClass2"
    def f1(self):
        print "Hello2"

class ChildMyClass(MyClass1, MyClass2):
    def __init__(self, data1, data2):
        super(ChildMyClass, self).__init__(data1)
        print "Child"
y=ChildMyClass(8,9)
y.f()
4

0 回答 0