Say I have the following code:
class Parent(object):
classattr1 = 'parent'
def __init__(self):
Parent.foo()
@classmethod
def foo(cls):
print cls.classattr1
class Child(Parent):
classattr1 = 'child'
def foo(cls):
raise Exception("I shouldn't be here")
Child()
In Parent.__init__, I need to call ‘foo’ that is defined within Parent, but I need to call it bound to Child, so that accessing cls.classattr1 will actually access the attribute as it is overridden in Child. Any ideas how to do this?
This should work:
but looks kinda evil.