Multiple Inheritance

Specification

     class A:
        def foo(self):
            print "Class A: foo"
     
     class B:
        def foo(self):
            print "Class B: foo"
        def bar(self):
            print "Class B: bar"
     
     class C(A,B):       # Inherits from class A and class B
        def spam(self):
            print "Class C: spam" 
  • Search for attributes is done using depth-first search in the order of base-classes
     c = C()
     c.foo()           # A.foo
     c.bar()           # B.bar
<<< O'Reilly OSCON 2000, Introduction to Python, Slide 98
July 17, 2000, beazley@cs.uchicago.edu
>>>