<p>Given the Python function:</p>

<pre><code>def a_method(arg1, arg2):
    pass
</code></pre>

<p>How can I extract the number and names of the arguments. I.e., given that I have a reference to <code>func</code>, I want the <code>func.[something]</code> to return <code>("arg1", "arg2")</code>.</p>

<p>The usage scenario for this is that I have a decorator, and I wish to use the method arguments in the same order that they appear for the actual function as a key. I.e., how would the decorator look that printed <code>"a,b"</code> when I call <code>a_method("a", "b")</code>?</p>

In CPython, the number of arguments is
```
```
a_method.func_code.co_argcount
```
```
and their names are in the beginning of
```
```
a_method.func_code.co_varnames
```
```
These are implementation details of CPython, so this probably does not work in other implementations of Python, such as IronPython and Jython.
One portable way to admit "pass-through" arguments is to define your function with the signature
```
func(*args, **kwargs)
```
. This is used a lot in e.g.
matplotlib
, where the outer API layer passes lots of keyword arguments to the lower-level API.