3

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?

2
  • BTW, I see that there's a PEP related to this: python.org/dev/peps/pep-0362 Commented Feb 8, 2010 at 19:56
  • What did help(foo) tell you? Commented Feb 8, 2010 at 19:58

1 Answer 1

4

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={})
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.