class MyClass(object):
def __init__(self):
self.var = "hi"
def some_method(self):
print self.var
#for the example below
myClass= MyClass()
So I understand that the following statements are equivelent.
myClass.some_method()
MyClass.some_method(myClass)
It takes object and passes it as the first argument self to some_method.
But when I do :
myClass= MyClass()
How does this flow work?
I am assuming its slightly different, and some magic happens behind the scenes (someone has some memory to allocate).
How does that translate to __init__(self) ? What is passed to __init__ MyClass ?
myClass= MyClass()callsMyClass.__new__method to create an instance ofMyClass. After thatMyClass.__init__is called with this instance as first argument.See the doc
object.__new__: