Name
getargspec, formatargspec
Synopsis
getargspec(f)
f is a
function object. getargspec returns a tuple with
four items
(
arg_names,
extra_args,
extra_kwds,
arg_defaults
).
arg_names is the sequence of names of
f’s formal arguments.
extra_args is the name of the special
formal argument of the form
*
args, or
None if f has no such
special argument. extra_kwds is the name
of the special formal argument of the form
**
kwds, or
None if f has no such
special argument. arg_defaults is the
tuple of default values for
f’s arguments. You can
deduce other details about
f’s signature from
getargspec’s results. For
example, f has
len(
arg_names
)-len(
arg_defaults
)
mandatory arguments, and the names of
f’s optional arguments
are the strings that are the items of the list slice
arg_names
[-len(
arg_defaults
):].
formatargspec accepts one to four arguments that
are the same as the items of the tuple that
getargspec returns, and returns a formatted string
that displays this information. Thus,
formatargspec(*getargspec(
f
))
returns a formatted string with
f’s formal arguments
(i.e., f’s
signature) in parentheses, as used in the
def statement that created
f.
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