The documentation for the inspect module says:
When the following functions return “frame records,” each record is a named tuple
FrameInfo(frame, filename, lineno, function, code_context, index)
. The tuple contains the frame object, the filename, the line number of the current line, the function name, a list of lines of context from the source code, and the index of the current line within that list.
What is actually a "frame object"? I was hoping to use this frame object to get a variable's value from the caller's globals()
:
import my_util
a=3
my_util.get_var('a')
and my_util.py
import inspect
def get_var(name):
print(inspect.stack()[1][0])