Rats! vararg assignments don't work
Maric Michaud
maric at aristote.info
Wed May 30 08:11:23 EDT 2007
samwyse a écrit :
> George Sakkis wrote:
>> On May 29, 11:33 pm, Matimus <mccre... at gmail.com> wrote:
>>
>>
>>> Your attemtp:
>>>
>>> [code]
>>> first, rest = arglist[0], arglist[1:]
>>> [/code]
>>>
>>> Is the most obvious and probably the most accepted way to do what you
>>> are looking for. As for adding the fucntionality you first suggested,
>>> it isn't likely to be implemented. The first step would be to write a
>>> PEP though.
>>
>> The time machine did it again: http://www.python.org/dev/peps/pep-3132/.
>
> Thanks! Now I just need to wait for Py3K and all of my problems will be
> solved. ;-)
>
> Actually, I'm surprised that the PEP does as much as it does. If tuples
> are implemented as S-expressions, then something like this:
> car, *cdr = tuple
> while leaving cdr a tuple would be trivial to implement. Of course, I'm
> an old-school LISPer, so what I consider surprising behavior doesn't
> always surprise anyone else, and vice versa.
Remember all these are copies of the original sequence, the lisp
equivalent to car/cdr is feasible with an iterator :
it = iter(seq)
car, cdr = it.next(), it
More information about the Python-list
mailing list