__init__
needs a two arguments, self
and an integer. Isn't that so simple?
For instance methods, Python will automatically pass a reference of the instance to your function. This is why all instance methods needs at least one argument, self
.
This is your case:
>>> class A:
def __init__(self)::
SyntaxError: invalid syntax
>>> class A:
def __init__(self):
print("Created!")
>>> a = A()
Created! #Success
>>> b = A.__init__()
Traceback (most recent call last):
File "<pyshell#13>", line 1, in <module>
b = A.__init__()
TypeError: __init__() missing 1 required positional argument: 'self'
Well, no wonder. __init__
needs an argument, but you're not passing anything.
However, if you insist on calling the function, you can just use another instance:
>>> b = A.__init__(a)
Created!
However this is just calling the function, and no new instance will be produced. b
is None
.