Packing a tuple and passing it to a function removes the first element

Asked by Ned

If I run the following code, both functions seem to remove the first element from the tuple. I don't unserstand why this is the case. Any help would be appreciated

sTestId = "100"

tRounds =("Morning","0700",
                 "Lunch","1200",
                 "Dinner","1600"
                  )

def func1(sTestId,*tRounds):
    print(tRounds)

def func2(sTestId,*tRounds):
    print(tRounds)

print(tRounds)
func2(*tRounds)
func1(*tRounds)

=======
OUTPUT
=======

('0700', 'Lunch', '1200', 'Dinner', '1600')
('Lunch', '1200', 'Dinner', '1600')
('Lunch', '1200', 'Dinner', '1600')

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Eugene S
Solved:
Last query:
Last reply:
Revision history for this message
Best Eugene S (shragovich) said :
#1

When you defined your functions, you stated that you were expecting a single argument (as sTestId) and a list of arguments (as *tRounds), then you pass the tuple you mentioned.
What happens is that your first argument "0700" is assigned to "sTestId" and the rest of the variables in tuple are assigned to "*tRounds". This is why you get such output.

If you want the whole list you can:
1. Remove the "sTestId" from function definition
2. Pass additional variable to a function (maybe that's what you had in mind) so it will be assigned to "sTestId" and the rest (the values in tuple) will be assigned to "*tRounds".

Cheers,
Eugene

Revision history for this message
Ned (nedleonard) said :
#2

Thanks Eugene S, that solved my question.