Python Glossary Русский

all Python 3inspectfunction

inspect.getargvalues()

stack and frames

Given a frame, returns ArgInfo: the argument names, the names of *args and **kwargs, and the frame's local variables.

Syntax

inspect.getargvalues(frame)

Values come from the local variables at the moment getargvalues runs, not from what was passed: if the function has already reassigned a parameter, you see the new value. Keyword-only parameters are listed in args alongside the regular ones. The 'deprecated' note in the 3.5 docs was a mistake; the function is supported. The result is the named tuple ArgInfo; the undocumented getargs and Arguments are its internals.

Examples

import inspect
def kw(a, *rest, b=1, **opts):
    a = a * 100
    frame = inspect.currentframe()
    try:
        info = inspect.getargvalues(frame)
        return info.args, info.varargs, info.keywords, info.locals['a']
    finally:
        del frame
print(kw(1))  # → (['a', 'b'], 'rest', 'opts', 100)

See also

Open in the full glossarydocs.python.orgReport an inaccuracy