TypeError: __init__() takes 1 positional argument but 2 were given
时间: 2023-11-07 21:35:47 浏览: 74
This error occurs when you try to call a function or method with more arguments than it is expecting. In this case, it looks like you are trying to initialize an object by calling its `__init__()` method with two arguments, but it is only expecting one.
To fix this error, you need to check the documentation for the object you are trying to initialize and make sure you are passing the correct number of arguments to its `__init__()` method. If you are unsure, you can also try printing out the object and its attributes to see what arguments it requires.
相关问题
TypeError:__init__ takes 1 positional argument but 5 were given
这个错误通常是因为在类的初始化函数中传递了错误的参数数量。在你提供的引用中,有三个例子都涉及到了这个错误。其中一个例子中,类的初始化函数中将init拼写成了int,也导致了这个问题。如果你遇到了这个错误,你需要检查类的初始化函数中传递的参数数量是否正确,并且确保没有拼写错误。如果你仍然无法解决这个问题,你可以查看相关文档或者寻求帮助。
TypeError: __init__() takes 1 positional argument but 3 were given
This error message is raised when you are trying to create an instance of a class with more arguments than the constructor method (__init__()) is expecting.
For example, if you have a class named "Person" that takes only one argument in its constructor method, but you pass three arguments while creating an instance of that class, you will get this error.
Here's an example:
```
class Person:
def __init__(self, name):
self.name = name
person1 = Person("John", 25, "Male")
```
In the above example, the Person class expects only one argument, which is the name of the person. However, while creating an instance of that class, we are passing three arguments - name, age, and gender. Hence, we get the TypeError: __init__() takes 1 positional argument but 3 were given error.
To fix this error, you need to make sure that the number of arguments you pass while creating an instance of a class matches the number of arguments expected by the constructor method.