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,
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.