Conversion from tuple to argument list?

Chris Liechti cliechti at gmx.net
Tue Nov 20 17:37:48 EST 2001


[posted and mailed]

"Bruce Edge" <bedge at troikanetworks.com> wrote in 
news:LEAK7.2203$px5.169125 at newsfeed.slurp.net:

> Forgive the stupid question, probably a C programmer mindset issue here.
>
> I have a tuple of data items say (0,1,2)  I want to pass to struct.pack,
> which takes:
>      pack (fmt, v1, v2, ...)
> 
> How can I pass my tuple to pack as its arg2,3,4,...
> 
> -TIA, Bruce.


>>> args = range(3)

newer python releases:
>>> struct.pack("bbb", *args)
'\x00\x01\x02'

any version:
>>> apply(struct.pack, ["bbb"] + list(args))
'\x00\x01\x02'
 
chris


-- 
Chris <cliechti at gmx.net>




More information about the Python-list mailing list