Passing a tuple to a function as multiple arguments

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ben Warren

    Passing a tuple to a function as multiple arguments

    Hello,

    Let's say I have a function with a variable number of arguments(pleas e 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



  • George Sakkis

    #2
    Re: Passing a tuple to a function as multiple arguments

    On Sep 6, 11:02 pm, Ben Warren <bwar...@qstrea ms.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

    Comment

    Working...