How does Python's super() work with multiple inheritance?
Python的super()在多继承下的方法推导顺序(MRO, Method Resolution Order)涉及到C3线性化算法(C3 linearization wiki)。其中关键是,
children precede their parents and the order of appearance in __bases__ is respected.
例子,
from collections import Counter, OrderedDict class OrderedCounter(Counter, OrderedDict): 'Counter that remembers the order elements are first encountered' def __repr__(self): return '%s(%r)' % (self.__class__.__name__, OrderedDict(self)) def __reduce__(self): return self.__class__, (OrderedDict(self),) oc = OrderedCounter('abracadabra') print oc
相关链接: