Something else needs to be considered when this type of error occurs:
I came across this error message and found this message helpful. It turns out that in my case, I redefined init (), where there was an inheritance of objects.
The inherited example is quite long, so I will move on to a simpler example that does not use inheritance:
class MyBadInitClass: def ___init__(self, name): self.name = name def name_foo(self, arg): print(self) print(arg) print("My name is", self.name) class MyNewClass: def new_foo(self, arg): print(self) print(arg) my_new_object = MyNewClass() my_new_object.new_foo("NewFoo") my_bad_init_object = MyBadInitClass(name="Test Name") my_bad_init_object.name_foo("name foo")
Result:
<__main__.MyNewClass object at 0x033C48D0> NewFoo Traceback (most recent call last): File "C:/Users/Orange/PycharmProjects/Chapter9/bad_init_example.py", line 41, in <module> my_bad_init_object = MyBadInitClass(name="Test Name") TypeError: object() takes no parameters
PyCharm did not notice this typo. Also Notepad ++ (other editors / IDE might).
Of course, this "takes no parameters" TypeError, it is not much different from "got two" while waiting for one, in terms of initializing the object in Python.
Topic addressing: the overload initializer will be used if it is syntactically correct, but if it is not ignored and the built-in will be used instead. The object will not wait / handle this, and the error will be reset.
In case of a sytax: error, the fix is โโsimple, just edit the custom init statement:
def __init__(self, name): self.name = name
Jonru2016 Jan 04 '16 at 4:33 2016-01-04 04:33
source share