假设我具有以下类结构
import abc
class Likelihood(object):
__metaclass__ = abc.ABCMeta
@abc.abstractmethod
def stat(self):
pass
@abc.abstractmethod
def pvalue(self):
pass
class B(Likelihood):
def stat(self):
return ('stat from B')
def pvalue(self):
which_stat = self.stat()
return ('pvalue from B using ' + which_stat)
class C(Likelihood):
def stat(self):
return ('stat from C')
def pvalue(self):
which_stat = self.stat()
return ('pvalue from C using ' + which_stat)
我想创建一个新的类D
,它同时具有B和C的pvalue
方法,但使用其自己的stat
方法。以下是具有所需方法输出的框架,
class D (B,C):
def stat(self):
return ('stat from D')
def pvalue_from_c(self):
# Desired output is 'pvalue from C using stat from D'
def pvalue_from_b(self):
# Desired output is 'pvalue from B using stat from D'
最蟒蛇的方式是什么?