+ 1

Python - TypeError: takes 2 positional arguments but 3 were given

Hi I am struggling with a problem in my python code. When I create an instance of the Teams() class I always get the traceback: line 16, in __init__ self.assign_team_number(self, name) TypeError: assign_team_number() takes 2 positional arguments but 3 were given I only pass 2 arguments but python seems to think it is 2 Here is my code. Please help. class Teams(): def __init__(self, name): self.assign_team_number(self, name) def assign_team_number(self, name): self.team_number = number_of_teams teams[number_of_teams] = name number_of_teams += 1

16th Aug 2020, 3:07 PM
Stephen
5 odpowiedzi
+ 1
I could be wrong, but you dont need the self tag in the constructor when you are calling the funktion. self.assign_team_number(name)
16th Aug 2020, 3:10 PM
Christian Hauck
Christian Hauck - avatar
+ 1
I created it like this: x = Teams("team x") It is working now that I removed self. Thanks so much
16th Aug 2020, 3:16 PM
Stephen
0
How did you create the instance that threw the error?
16th Aug 2020, 3:10 PM
Slick
Slick - avatar
0
I run your code but I didn't find any errors.
16th Aug 2020, 3:12 PM
Allamprabhu Hiremath