Accessing all function argmuments
<p>I have a function with 4 arguments and want to check those 4 arguments for something.
Currently I do it like this:</p>

<pre><code>def function1(arg1, arg2, arg3, arg4):
    arg1 = function2(arg1)
    arg2 = function2(arg2)
    arg3 = function2(arg3)
    arg4 = function2(arg4)

def function2(arg):
    arg = dosomething(arg)
    return arg
</code></pre>

<p>I think this is not really a nice way to do it, so my idea is to do something like this:</p>

<pre><code>def function1(arg1, arg2, arg3, arg4):
    for arg in listOfArguments:
        arg = function2(arg)


def function2(arg):
    arg = checkSomething(arg)
    return arg
</code></pre>

<p>Is there a way in Python to get a list of all the arguments passed to <code>function1</code>?</p>

<p>Thanks for your help and ideas.</p>

<p>Yes, use <code>*args</code>:</p>

<pre><code>In [1]: def func(*args):
   ...:     print(len(args), args)
   ...:     

In [2]: func(1, 2, 3, 4)
4 (1, 2, 3, 4)
</code></pre>

<p>More information can be found <a href="https://pythontips.com/2013/08/04/args-and-kwargs-in-python-explained/" rel="nofollow">here.</a></p>

python function python-3.x