I have many derived classes of foo class and I am trying to instantiate object of base class to one of derived classes. I want to call constructor of base class only once. I am getting runtime error while I am trying to execute following piece of code:
class foo():
call_once = True
_Bar = None
_BaseClass = None
def __init__(self):
if (self.call_once):
self.call_once = False
self._Bar = bar()
self._BaseClass = _bar
class bar(foo):
def __init__(self):
foo.__init__(self)
bar1 = bar()
fooinstances that aren't initialized? Why is the first one special? Whatever you're doing, I guarantee there's a better way to do it.foo()instantiates an object of typebar. Butbar()calls the__init__method offoo(), which in turn instantiates an object of typebar. This results in an infinite loop. Theifstatement does not help here, since the recursion occurs within theifblock.