【发布时间】:2018-05-28 06:45:30
【问题描述】:
class First(object):
def __init__(self):
print("first")
class Second(First):
def __init__(self):
print("second")
class Third(First, Second):
def __init__(self):
print("third")
为什么 Python 不能创建一致的 MRO?在我看来这很清楚:
- 如果方法在第三个中不存在,则在第一个中搜索
- 如果方法在 First 中不存在,则在 Second 中搜索
但如果你尝试一下:
TypeError: Error when calling the metaclass bases
Cannot create a consistent method resolution
order (MRO) for bases First, Second
【问题讨论】:
标签: python multiple-inheritance