How to convert a list/tuple into an function argument list easily?
Gerhard Haering
gerhard.haering at gmx.de
Sun Dec 15 21:37:29 EST 2002
* Pierre Rouleau <pieroul at attglobal.net> [2002-12-15 21:20 -0500]:
> [...] is there an easy way to convert a tuple into all of its elements so that
> i could write something like:
>
> val = struct.pack('<LHH', elementsOf(record))
Yes, there is:
def foo(x, y): return x + y
args = [3, 4]
print foo(*args)
there also the older way to do it with apply:
print apply(foo, args)
-- Gerhard
PS: In addition to the *args form, there is also the **kwargs form for keyword
arguments.
More information about the Python-list
mailing list