Name
getargvalues, formatargvalues
Synopsis
getargvalues(f)
f is a frame object, for example the
result of a call to the function _getframe in
module sys (covered in Chapter 8) or to function
currentframe in module inspect.
getargvalues returns a tuple with four items
(
arg_names,
extra_args,
extra_kwds,
locals
).
arg_names is the sequence of names of
f’s
function’s formal arguments.
extra_args is the name of the special
formal argument of form
*
args, or
None if
f’s function has no such
special argument. extra_kwds is the name
of the special formal argument of form
**
kwds, or
None if
f’s function has no such
special argument. locals is the dictionary
of local variables for f. Since arguments,
in particular, are local variables, the value of each actual argument
can be obtained from locals by indexing
the locals dictionary with the
argument’s name.
formatargvalues accepts one to four arguments that
are the same as the items of the tuple that
getargvalues returns, and returns a formatted
string that displays this information.
formatargvalues(*getargvalues(
f
))
returns a formatted string with
f’s actual arguments in
parentheses, in named (keyword) form, as used in the call statement
that created f. For example:
def f(x=23): return inspect.currentframe( ) print inspect.formatargvalues(inspect.getargvalues(f( ))) # prints: (x=23)
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access