471,330 Members | 1,813 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,330 software developers and data experts.

Passing a tuple to a function as multiple arguments

Hello,

Let's say I have a function with a variable number of arguments(please ignore syntax errors):

def myfunc(a,b,c,d,...):

and I have a tuple whose contents I want to pass to the function. The number of elements in the tuple will not always be the same.

T = A,B,C,D,...

Is there a way that I can pass the contents of the tuple to the functionwithout explicitly indexing the elements? Something like:

myfunc(magic(T))

where magic() expands the tuple to its multiple elements. I'vetried various for loop constructs, but everything I can think of returns alist, which doesn't work because it's viewed as one parameter.
thanks,
Ben

Sep 7 '07 #1
1 7472
On Sep 6, 11:02 pm, Ben Warren <bwar...@qstreams.comwrote:
Hello,

Let's say I have a function with a variable number of arguments (please ignore syntax errors):

def myfunc(a,b,c,d,...):

and I have a tuple whose contents I want to pass to the function. The number of elements in the tuple will not always be the same.

T = A,B,C,D,...

Is there a way that I can pass the contents of the tuple to the function without explicitly indexing the elements?
Yes:

myfunc(*T)

More details at http://docs.python.org/tut/node6.htm...00000000000000
HTH,
George

Sep 7 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by Kay Schluehr | last post: by
2 posts views Thread by imdognuts | last post: by
11 posts views Thread by montyphyton | last post: by
21 posts views Thread by Martin Geisler | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.