I have the following piece of code that is bugging me:<br><br>#-------------------------------------------------------------------------------<br>def someFunc(arg1, arg2=True, arg3=0):<br> print arg1, arg2, arg3<br><br>
someTuple = (<br> ("this is a string",),<br> ("this is another string", False),<br> ("this is another string", False, 100)<br>)<br><br>for argList in someTuple:<br> if len(argList) == 1:<br>
someFunc(argList[0])<br> elif len(argList) == 2:<br> someFunc(argList[0], argList[1])<br> elif len(argList) == 3:<br> someFunc(argList[0], argList[1], argList[2])<br>#-------------------------------------------------------------------------------<br>
<br>Is it possible to rewrite this code so I don't have that awkward if statement at the bottom that passes every variation in the number of arguments to the function? I know that it's possible to define a function to accept a variable number of parameters using *args or **kwargs, but it's not possible for me to redefine this function in the particular project I'm working on.<br>
<br>What I would really like to do is something like this (pseudocode) and do away with the if statement completely:<br><br>#-------------------------------------------------------------------------------<br>
def someFunc(arg1, arg2=True, arg3=0):<br>
print arg1, arg2, arg3<br>
<br>
someTuple = (<br>
("this is a string",),<br>
("this is another string", False),<br>
("this is another string", False, 100)<br>
)<br>
<br>for argList in someTuple:<br> someFunc(expandArgList(argList))<br>#-------------------------------------------------------------------------------<br><br>Is this possible? Thanks in advance.<br>