Tuples -> Function Params?

Don O'Donnell donod at home.com
Tue Dec 4 05:12:52 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...
> 
> --
> Philip Sw "Starweaver" [rasx] :: <nothing>

Philip:

What you want is:

glColor3f(*self.color)

As a matter if interest, 
you can also pass a dictionary as:

func(**dict)

i.e.:
>>> def triple(a,b,c):
... 	print "%s : %s : %s" % (a,b,c)
... 	
>>> t = (12, 15, 18)
>>> triple(1,2,3)
1 : 2 : 3
>>> triple(*t)
12 : 15 : 18
>>> dic = {'a':'x','b':'y','c':'z'}
>>> triple(**dic)
x : y : z

I can't find it in the docs now either.  
But I know it's a fairly recent addition. 
2.1 perhaps?

Cheers,
Don



More information about the Python-list mailing list