Question

I've a class calling another class's function, like this:

self.pool.get('some_value')

How do I get the caller class inside the get function ?

thanks before,

Was it helpful?

Solution

You can do this via inspect. The contents of the get() function can be:

import inspect
myCaller = inspect.currentframe().f_back.f_locals['self']

After that, you have the caller's instance refered to by myCaller.

Disclaimer: this is not a good practice, because it ruins the whole point of encapsulation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top