Tuples -> Function Params?

Fernando Pérez fperez528 at yahoo.com
Sun Dec 2 21:24:59 EST 2001


Philip Swartzleonard wrote:

>     Just a quick question, right now i'm doing this:
> 
> self.color = afloat,bfloat,cfloat
> .
> . (change functions)
> .
> a,b,c = self.color
> glColor3f(a,b,c)
> 
>     [actual function dosen't mater except that it isn't something i
>     can
> just change]
> 
>     Ok, the question is, is there a way to do this where i don't
>     unpack
> the tuple and pass sepearte arugments? This would be most
> convienent. Function(tuple) doesn't work... and i couldn't seem to
> find any other info in the docs...
>

The *args syntax is probably what you want:
 
In [1]: args = (1,2,3)
In [2]: def f(x,y,z): print x+y+z
   ...:

# this won't work:
In [3]: f(args)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call 
last)
 
?
 
TypeError: f() takes exactly 3 arguments (1 given)

# but this will:
In [4]: f(*args)
6



More information about the Python-list mailing list