The issue here is I want to pass a tuple as an argument to a second function. Before there are outcries of "duplicate!" I have already looked at a post regarding a similar question Expanding tuples into arguments
Here is the code I am testing with:
def producer(): return ('a','b') def consumer(first, second, third): print first+second+third arg = producer() consumer(*arg, 'c') # expected abc This outputs the error:
There's an error in your program *** only named arguments may follow *expression This useful error message has led switch the order of arguments to consumer('c', *arg), but this does not quite solve the issue as it will output 'cab'.
So my question is, is there a better way to pass in a tuple to a multi argument function, and preserve the ordering?
Also for bonus points, what does the '*' operator do? (this was not explained in the previous post)
*does. It is not an operator.func(*args, arg)and many other unpacking variations legal in some future Python version. See also issue 2292 which discusses attempts at implementing this behavior. Alas, there doesn't seem to have been much progress in the last year or so.