I'm trying something very basic with Python inheritance:
class Parent:
def __init__(self):
self.text = 'parent'
def getText(self):
print self.text
class Child1(Parent):
def __init__(self):
self.x = 'x'
class Child2(Parent):
def __init__(self):
self.x = 'x'
if __name__ == "__main__":
parent = Parent()
child1 = Child1()
child2 = Child2()
parent.getText()
child1.getText()
child2.getText()
but I keep getting
Child1 instance has no attribute 'text'
how are variables passed to children?
self.textis initialize inParentconstructor which is never called.super().__init__()?pass, that's what it's for (a dummy body).pass, e.g.if a: pass(only for demonstration purpose).pass, if the block is also a function, then adding a docstring also works to prevent python from complaining about the indentation being wrong.