python - Why not constructor of super class invoked when we declare the object of sub class? -
i java programmer, beginner in python programming. have noticed unexpected behavior in python programming. expecting print sequence b class ,a class
constructors. it's executing constructor of only.
output "its constructor of a",could please me understand flow of execution. in advance
class b: def __init__(self): print 'its constructor of b' class a(b): def __init__(self): print 'its constructor of a' #b.__init__(self) if __name__=='__main__': obj=a()
in python should call parent's initializer (that's how __init__
method called, - "constructor" else) explicitly.
you can did in commented out line. better yet, should use super
function, figures out, parent access you. works new-style classes though (basically, means, root of class hierarchy must inherit object
).
Comments
Post a Comment