Let's say I have a function in Python like so:
def foo(x): pass
According to Python, 'foo' alone is a function reference, right?
>>> def foo(x): pass
...
>>> foo
<function foo at 0xb7f3d1b4>
Is there any way I can examine the function reference to determine the number of arguments it expects?
You need inspect.getfullargspec
in py3k or inspect.getargspec
in earlier versions.
>>> def foo(x): pass
>>> import inspect
>>> inspect.getfullargspec(foo)
FullArgSpec(args=['x'], varargs=None, varkw=None, defaults=None, kwonlyargs=[], kwonlydefaults=None, annotations={})
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.