In the following sample, is there a magic word I can put in place of <ChildClass> that works like the opposite of super?
class Parent(object):
def __init__(self):
print <ChildClass>.x
class someChild(Parent):
x = 10
It is a stupid example, but it shows my intention. By the way, using someChild will not work, because there are many child classes.
The only solution I can think of is to have a constructor in every child class that calls the constructor of Parent with a reference to itself (or even to pass x), but I would like to avoid having a constructor at all in each child.
What is wrong with just using
self.x?Note how this works even if
Parenthas a class attributexas well (Nonein the above example)- the child’s takes precedence.