0

I am having a little hard time understanding why this is happening. So far from what I have read about python is that the initializer of a base class needs to be explicitly called by the derived class.This is one of the source that confirms my understanding. However the following example baffles me

class foo(object) :
  def __init__(self,par):
    print "Inside foo constructor"

class bar(foo):
  status_code = 302

b = bar(23)

In the above case the derived class does not have an initializer. So will it be correct for me to assume that the reason why the initializer of the base class is being called is because its being inherited by the derived class.

Community
  • 1
  • 1
James Franco
  • 4,516
  • 10
  • 38
  • 80

1 Answers1

2

I believe that you have to explicitly call the base class's __init__ only if you define __init__ of the derived class. Otherwise it will be called automatically. This is actually exactly what the answer you link says.

gandaliter
  • 9,863
  • 1
  • 16
  • 23