Understanding multiple inheritance and method resolution order in Python

# cat multiple_inheritance.py 
import inspect

class A(object): pass

class B(A): pass

class C(A): pass

class D(B): pass

class E(C): pass

class F(D, E): pass

print inspect.getmro(A)
print inspect.getmro(B)
print inspect.getmro(C)
print inspect.getmro(D)
print inspect.getmro(E)
print inspect.getmro(F)

# python multiple_inheritance.py 
(<class '__main__.A'>, <type 'object'>)
(<class '__main__.B'>, <class '__main__.A'>, <type 'object'>)
(<class '__main__.C'>, <class '__main__.A'>, <type 'object'>)
(<class '__main__.D'>, <class '__main__.B'>, <class '__main__.A'>, <type 'object'>)
(<class '__main__.E'>, <class '__main__.C'>, <class '__main__.A'>, <type 'object'>)
(<class '__main__.F'>, <class '__main__.D'>, <class '__main__.B'>, <class '__main__.E'>,

Comments

Popular posts from this blog

Multiple repeat error when the regex has multiple wildcards in python re module

Avoid using global/class-level mutable datatypes like list/dicts

Weakref proxy is for instance only ...