all Python 3inspectfunction
inspect.formatargvalues()
stack and frames
Turns the result of getargvalues() into a string like (x=1, y=2, *rest=(3,)), handy for a debug log of calls.
Syntax
inspect.formatargvalues(*inspect.getargvalues(frame))
Unpack ArgInfo with a star: formatargvalues(*inspect.getargvalues(f)). It shows the current values of local variables, so call it at the top of the function before parameters are reassigned. For call logging from a decorator, Signature.bind() is simpler and more reliable than reading frames. Annotations are turned into text by the undocumented formatannotation and formatannotationrelativeto.
Examples
import inspect
def add(x, y=10, *rest, **opts):
frame = inspect.currentframe()
try:
return inspect.formatargvalues(*inspect.getargvalues(frame))
finally:
del frame
print(add(1, 2, 3, k=4)) # → (x=1, y=2, *rest=(3,), **opts={'k': 4})
See also
Open in the full glossarydocs.python.orgReport an inaccuracy