0

i am working with inheritence,here i got output for single inheritence but multiple inheritence showing error.so please help me.I don't have any knowledge about mro in python.please give me good advice.

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())

Above code giving following Error:-

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

Thank you.

5
  • 1
    Count the leading underscores in ___init__ in Carrier? Commented Apr 1, 2018 at 15:14
  • 1
    You defined Carrier.___init__ (3 leading underscores). Commented Apr 1, 2018 at 15:14
  • @JonClements thanks a lot,sorry for my silly mistake Commented Apr 1, 2018 at 15:42
  • @CristiFati thanks cristi. Commented Apr 1, 2018 at 15:43
  • On a side note, this is not a good use of inheritance. That is a Player cannot be said to be an instance of an (IPL) team. A player is a member of team. That team and league can change, which is not something inheritance could express. Things get stranger when you realise you saying an auction is an instance of a player too. A better use of inheritance might be types of team. That is T20 and Test cricket are substantially different, especially as Test teams are international and have different rules about who can be a member of the team. Commented Apr 1, 2018 at 16:03

1 Answer 1

1

I think the problem is that your __init__ has three underscores instead of two:

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

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

should be:

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

    def disp(self):
         return "Wickets:"+self.wicket+"Runs:"+self.run
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.