__init__() takes from 1 to 2 positional arguments but 3 positional arguments (and 1 keyword-only argument) were given
时间: 2023-10-31 07:08:06 浏览: 78
This error message is indicating that the "__init__()" method (constructor) of a class is expecting either 1 or 2 positional arguments, but it received 3 positional arguments and 1 keyword-only argument.
A positional argument is a parameter that is passed to a function based on its position in the parameter list. For example, in the following function definition, "x" and "y" are positional arguments:
```python
def add(x, y):
return x + y
```
A keyword-only argument is an argument that can only be passed by name and cannot be passed positionally. For example, in the following function definition, "z" is a keyword-only argument:
```python
def multiply(x, y, *, z):
return x * y * z
```
To fix the error, you need to make sure that the number and type of arguments passed to the "__init__()" method matches the parameter list of the method. If you are calling the method yourself, you should check the number and type of arguments you are passing. If you are using a library or framework that is calling the method for you, you should consult its documentation to see what arguments it expects.
阅读全文