How to use inspect to get the caller's info from callee in Python?
I need to get the caller info (what file/what line) from callee. I learned that I can use inpect module for that for purposes, but not exactly how. How to get those info with inspect? Or is there any other way to get the info? import inspect print __file__ c=inspect.currentframe() print c.f_lineno def hello(): print inspect.stack ?? what file called me in what line? hello() The caller's frame is one frame higher than the current frame. You can use inspect.currentframe().f_back to find the caller's frame. Then use inspect.getframeinfo to get the caller's filename and line number. import inspect