File: class/Workbook/Examples/Lecture7/mi.py

class Super1:
    def method2(self):             # a 'mixin' superclass
        print 'in Super1.method2'

class Super2:
    def method1(self):
        self.method2()             # calls my method2??
    def method2(self):
        print 'in Super2.method2'

class Sub1(Super1, Super2):
    pass                           # gets Super1's method2

class Sub2(Super2, Super1):
    pass                           # gets Super2's method2

class Sub3(Super1, Super2):
    method2 = Super2.method2       # pick method manually

Sub1().method1()
Sub2().method1()
Sub3().method1()




[Home page] Books Code Blog Python Author Train Find ©M.Lutz