Consider the code in the file my_module.py:
class A(object):
def __init__(self, x=er()):
self.x = x
Now, when I import this module
import my_module
I get an error,
name 'er is not defined
While I understand that my_module does not have er
defined, but I am never creating an instance of class A
. Therefore it is puzzling that python tries to execute the __init__
callback when simply importing the module. Although, the __init__
call is not fully executed as explained by the example below:
class A(object):
def __init__(self, x=5):
self.x = x
print ('I am here')
Now, when I import the module - nothing is printed and this is expected behavior.
I am puzzled why is function er
called in the first example when I donot instantiate an object of class A
. Any pointers to the documentation that explains this?