Is there some built-in way in Python to get a reference to the ‘Callers’ instance? We know this must be stored in Python somewhere otherwise it wouldn’t know where to send the the return value to. Sure it could be passed as a parameter but why go to that overhead as it already exists somewhere. See example code:
class Callee():
def method(self):
print("Caller.ClassVar:", Caller.ClassVar)
# print("Caller.InstVar:", Caller.InstVar) # <- this fails because instance of Caller is not available
return "retVal"
class Caller():
ClassVar = "var1"
def __init__(self):
self.InstVar = "var2"
oCallee = Callee()
print("return from oCallee.method():", oCallee.method())
oCaller = Caller()