Rats! vararg assignments don't work

samwyse dejanews at email.com
Tue May 29 23:06:06 EDT 2007


I'm a relative newbie to Python, so please bear with me.  After seeing 
how varargs work in parameter lists, like this:
     def func(x, *arglist):
and this:
     x = func(1, *moreargs)
I thought that I'd try this:
     first, *rest = arglist
Needless to say, it didn't work.  That leaves me with two questions.

First, is there a good way to do this?  For now, I'm using this:
     first, rest = arglist[0], arglist[1:]
but it leaves a bad taste in my mouth.

Second, is there any good reason why it shouldn't work?  It seems like 
such an obvious idiom that I can't believe that I'm the first to come up 
with the idea.  I don't really have the time right now to go source 
diving, so I can't tell if it would be wildly inefficient to implement.

Thanks!



More information about the Python-list mailing list