What's the best way of having a child class (B) instance call one of its parent class (A) instance's methods? Passing self
into the instance of the child class (B) seems to work, but somehow that doesn't seem to be efficient or good practice. Any better ways of going about this?
class A():
def __init__(self,name):
self.instanceOfB = self.B(self)
self.name = name
def hello(self):
print 'Hello '+self.name
class B():
def __init__(self,parent):
self.parent = parent
def hi(self):
self.parent.hello() ##Call parent instance's method 'hello()' here
instanceOfA = A('Bob')
instanceOfA.instanceOfB.hi()
Should result in:
Hello Bob
@classmethod
and @staticmethod
only work if A.hello()
does not depend on any information instantiated with class A