Questo è quello che sto cercando di fare in Python:Python eredità e genitore chiama costruttore di classe
class BaseClass:
def __init__(self):
print 'The base class constructor ran!'
self.__test = 42
class ChildClass(BaseClass):
def __init__(self):
print 'The child class constructor ran!'
BaseClass.__init__(self)
def doSomething(self):
print 'Test is: ', self.__test
test = ChildClass()
test.doSomething()
che si traduce in:
AttributeError: ChildClass instance has no attribute '_ChildClass__test'
Che cosa dà? Perché non funziona come mi aspetto?
call baseclass .-- init-- prima di fare qualsiasi altra cosa per riferimento futuro, –