+ 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
4 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)
+ 1
I created it like this: x = Teams("team x")
It is working now that I removed self. Thanks so much
0
How did you create the instance that threw the error?
0
I run your code but I didn't find any errors.