How to access the calling/outer/container python class within current class when added as a property. Consider this example…
class a():
@staticmethod
def meth():
print 'Who called me?'
class b():
my_a = a
class c():
my_a = a
b.my_a.meth()
>> Who called me?
c.my_a.meth()
>> Who called me?
So the question in this example is how to know within a.meth() whether it is being called from class b or class a?
The above are obviously static classes and methods, would the solution to the above also apply to containing objects?
There’s no good way to know how the meth() function was accessed. By the time it is called, it is simply a function. If you use @classmethod instead, you will at least get the class passed to you, but in this case, they are both the same
a, so I’m not sure you’ll get what you want.You will likely need to do some more bookkeeping to get the information you want.