python“object .__ init __()中的多重继承不带参数

时间:2018-04-01 15:11:00

标签: python multiple-inheritance

我正在与之合作 继承,这里我得到了单一继承的输出但多重继承显示错误。所以请帮助我。我对python中没有任何关于mro的知识。请给我很好的建议。

class Player:
    def __init__(self,name,country):
        self.name=name
        self.country=country

    def info(self):
        return self.name+":"+self.country

class Ipl(Player):
    def __init__(self,name,country,team):
        Player.__init__(self,name,country)
        self.team=team

    def info_ipl(self):
        return self.info()+"\nIpl team:"+self.team


x=Ipl("Suresh Raina","India","csk")    
print(x.info_ipl())


class Carrier:
    def ___init__(self,wicket,run):
        self.wicket=wicket
        self.run=run

    def disp(self):
        return "Wickets:"+self.wicket+"Runs:"+self.run



class Aauction(Ipl, Carrier):

    def  __init__(self,wicket,run,name,country,team):

        Ipl.__init__(self,name,country,team)
        Carrier.__init__(self,wicket,run)
        self.Innings=Innings


    def stati(self):
        return  self.info_ipl()+","+self.disp()+"Total Innings:"



x = Aauction(150,2000,"Suresh_Raina","India","kkr")
print(x.stati())

以上代码给出以下错误: -

Suresh Raina:India
Ipl team:csk
Traceback (most recent call last):
  File "C:\Users\Rahul\Desktop\PYTHON\EXP8.py", line 49, in <module>
    x = Aauction(150,2000,"Suresh_Raina","India","kkr")
  File "C:\Users\Rahul\Desktop\PYTHON\EXP8.py", line 40, in __init__
    Carrier.__init__(self,wicket,run)
TypeError: object.__init__() takes no parameters

谢谢。

1 个答案:

答案 0 :(得分:1)

我认为问题是你的__init__有三个下划线而不是两个:

class Carrier:
    def ___init__(self,wicket,run):
        self.wicket=wicket
        self.run=run

    def disp(self):
        return "Wickets:"+self.wicket+"Runs:"+self.run

应该是:

class Carrier:
    def __init__(self,wicket,run):
         self.wicket=wicket
         self.run=run

    def disp(self):
         return "Wickets:"+self.wicket+"Runs:"+self.run