pythonlistparameterslong-parameter-list

Python function long parameter list


I'm looking for the best way to give a list of arguments to my function :

def myFunc(*args):
    retVal=[]
    for arg in args:
        retVal.append(arg+1)
    return "test",retVal

The problem is that it becomes very annoying when you have a long list of parameters to pass to your function because you have to write two times your whole list of parameters and When you have 10 parameters or more with complete names, it becomes really (really) heavy.

test,alpha,beta,gamma,delta,epsilon,zeta,eta,theta,iota=myFunc(alpha,beta,gamma,delta,epsilon,zeta,eta,theta,iota)

So I thought about something like this :

w=alpha,beta,gamma,delta,epsilon,zeta,eta,theta,iota
test,w=myFunc(w)

But then I sill have to do :

alpha,beta,gamma,delta,epsilon,zeta,eta,theta,iota=w

Is there any shorter way to give and get back a list of parameter from a function. Or give a pointer to the function for it to modify directly the parameters ?

This is what I'm looking for :

w=alpha,beta,gamma,delta,epsilon,zeta,eta,theta,iota
test,w=myFunc(w)

# And directly get my parameters modified to be able to print them :
print alpha,[...],iota

Solution

  • Simply make the function return a dict. Then you can call it using myFunc(**yourdict) to use the dict items as arguments and if you return yourdict you get back the same dict (with probably modified values) - or you just modify the original dict and don't return one at all.