【发布时间】:2013-04-29 16:02:17
【问题描述】:
我在 Python 中使用多重继承时遇到了一些问题,无法理解我做错了什么。
我有三个类 A、B、C 定义如下,它不起作用。
class A(object):
def __init__(**kwargs):
.
.
class B(object):
def __init__(**kwargs):
# prepare a dictionary "options" with the options used to call A
super(B,self).__init__(**options)
def coolmethod(x):
#some cool stuff
对于 A 和 B 我没有任何问题。
我想创建一个继承自 A 和 B 的第三类 C 这样我就可以使用B中定义的coolmethod,但想使用A中定义的构造函数。
尝试定义 class C(A,B) 不起作用,因为未定义 MRO。
但定义 class C(B,A) 不允许我使用 A.init 而不是 B.init。
我该如何解决这个问题?
【问题讨论】:
标签: python python-2.7 multiple-inheritance method-resolution-order