Python coding style when calling a function with multiple parameters

This may sound like a newbie question, but I really need help. I don’t even know how to tag it, but I guess this is just a Python question. I need to use a function that takes 5 parameters and returns 5 values:

a, b, c, d, e = function (input1, input2, input3, input4, input5) 

The problem is that when I use the full names of variables / functions, the line is too long and the code looks ugly, I want to use a more fancy solution here, and I thought about using a dict or list, so I can do this:

 input_dict['param1'] = input1 input_dict['param2'] = input2 input_dict['param3'] = input3 input_dict['param4'] = input4 input_dict['param5'] = input5 ret_dict = function(input_dict) 

Is there a better or “pythonic” way to improve the quality of the code for this kind of call?

Thanks in advance!

+6
source share
1 answer

You can nest lines like this

 my_function(test, this, out, like, so, something, indent) 

You can expand the lists into such arguments

 a = [1,2,3,4,5] my_function(*a) 

You can even do it

 result = my_function(big, long, list, of, args) a,b,c,d = result 

In addition, PEP-8 has good guidelines for working with string lengths. - Lattyware 5 minutes ago

+10
source

All Articles