我刚开始学习Python,我不太明白代码中的问题在哪里。我有一个带有两个方法的基类Proband,我想创建一个子类Gesunder,我想覆盖属性idn,artefakte。你知道吗
import scipy.io
class Proband:
def __init__(self,idn,artefakte):
self.__idn = idn
self.artefakte = artefakte
def getData(self):
path = 'C:\matlab\EKGnurbild_von Proband'+ str(self.idn)
return scipy.io.loadmat(path)
def __eq__(self,neueProband):
return self.idn == neueProband.idn and self.artefakte == neueProband.artefakte
class Gesunder(Proband):
def __init__(self,idn,artefakte,sportler):
super().__init__(self,idn,artefakte)
self.__sportler = sportler
hans = Gesunder(2,3,3)
super()
调用应修改为:你的代码有两个问题。在python 2中:
super()
有两个参数:类名和实例super()
,基类必须从object
继承所以你的代码变成:
注意对
super(Gesunder, self).__init__
的调用没有self
作为第一个参数。你知道吗在python2中,
super()
本身是无效的。相反,您必须使用super(ClassName, self)
。你知道吗相关问题 更多 >
编程相关推荐