Using multiple "*"-style arguments

Dave Opstad dave.opstad at
Fri Jun 18 16:25:28 CEST 2004

File this one under "enhancement request" I guess, but it would sure be 
nice. I wrote this line the other day, thinking it would just work:

x = struct.pack(">HhhhhhhHHHL", i, *bounds, *b[0:2], *b[6:9], len(s))

Unfortunately, it doesn't. The only valid place for an "*"-style 
argument is at the end of the arguments list. But this line seems so 
natural! Since struct.pack expects all its arguments separately (rather 
than gathered into a list or tuple), I have to be able to accommodate 
its needs, and since I had several arguments already in lists, I thought 
I could get away with this notation.

Certainly I can get around this limitation by either spelling out the 
arguments (i.e. b[0], b[1], b[6]...), or by writing multiple lines of 
code to gather the arguments into a single list which could then have 
the "*" applied. But I'd love a simpler, more compact notation, not 
unlike what I've written above. Does anyone know of a current Python 
idiom for unravelling list arguments in calls?


More information about the Python-list mailing list