I'd like to pass a tuple (or maybe a list) to a function as a sequence of values (arguments). The tuple should be then unpacked as an argument into *arg.
For example, this is clear:
def func(*args):
for i in args:
print "i = ", i
func('a', 'b', 3, 'something')
But what I want to do is this:
tup = ('a1', 'a2', 4, 'something-else')
func(tup)
And this should behave similar to the first case.
I think I should use here reprint and eval but not sure how exactly.
I know that I can just pass the tuple in the function and then unpack it within the body, but my question here is how to unpack it in the function call itself.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…