【发布时间】:2013-12-25 09:34:14
【问题描述】:
所以,我有这样的情况。
class A(object):
def foo(self, call_from):
print "foo from A, call from %s" % call_from
class B(object):
def foo(self, call_from):
print "foo from B, call from %s" % call_from
class C(object):
def foo(self, call_from):
print "foo from C, call from %s" % call_from
class D(A, B, C):
def foo(self):
print "foo from D"
super(D, self).foo("D")
d = D()
d.foo()
代码的结果是
foo from D
foo from A, call from D
我想从D 类调用所有父方法,在本例中为foo 方法,而不像A 那样在父类中使用super。我只想从D 类中调用超级。 A、B 和 C 类就像 mixin 类,我想从 D 调用所有 foo 方法。我怎样才能做到这一点?
【问题讨论】:
-
查看
class super([type[, object-or-type]])for python3
标签: python class inheritance multiple-inheritance