TypeError __init__ takes 1 positional argument but 2 were given
This error message typically occurs when you are trying to create an instance of a class and passing in more arguments than the constructor expects.
For example, if you have a class with a constructor that takes one argument:
class MyClass:
def __init__(self, arg):
self.arg = arg
And you try to create an instance of the class with two arguments:
my_instance = MyClass('arg1', 'arg2')
You will get the error message:
TypeError: __init__() takes 1 positional argument but 2 were given
To fix this error, make sure that you are passing in the correct number of arguments to the constructor. In the example above, you would need to remove the extra argument:
my_instance = MyClass('arg1')
原文地址: https://www.cveoy.top/t/topic/bK4I 著作权归作者所有。请勿转载和采集!