[Python-3000] PEP 3132: Extended Iterable Unpacking
g.brandl at gmx.net
Wed May 2 09:04:29 CEST 2007
Guido van Rossum schrieb:
> On 5/1/07, Georg Brandl <g.brandl at gmx.net> wrote:
>> This is a bit late, but it was in my queue by April 30, I swear! ;)
>> Comments are appreciated, especially some phrasing sounds very clumsy
>> to me, but I couldn't find a better one.
>> PEP: 3132
>> Title: Extended Iterable Unpacking
>> Version: $Revision$
>> Last-Modified: $Date$
>> Author: Georg Brandl <georg at python.org>
>> Status: Draft
>> Type: Standards Track
>> Content-Type: text/x-rst
>> Created: 30-Apr-2007
>> Python-Version: 3.0
>> This PEP proposes a change to iterable unpacking syntax, allowing to
>> specify a "catch-all" name which will be assigned a list of all items
>> not assigned to a "regular" name.
>> An example says more than a thousand words::
>> >>> a, *b, c = range(5)
>> >>> a
>> >>> c
>> >>> b
>> [1, 2, 3]
> Has it been pointed out to you already that this particular example is
> hard to implement if the RHS is an iterator whose length is not known
> a priori? The implementation would have to be quite hairy -- it would
> have to assign everything to the list b until the iterator is
> exhausted, and then pop a value from the end of the list and assign it
> to c.
Yes, that is correct. My implementation isn't *that* hairy, though, it's
only 13 lines of code more.
I'll post the patch to SourceForge later today.
> it would be much easier if *b was only allowed at the end. (It
> would be even worse if b were assigned a tuple instead of a list, as
> per your open issues.)
The created tuple is a fresh one, so can't I just copy pointers like from a
list and set ob_size later?
> Also, what should this do? Perhaps the grammar could disallow it?
> *a = range(5)
I'm not so sure about the grammar, I'm currently catching it in the AST
Thus spake the Lord: Thou shalt indent with four spaces. No more, no less.
Four shall be the number of spaces thou shalt indent, and the number of thy
indenting shall be four. Eight shalt thou not indent, nor either indent thou
two, excepting that thou then proceed to four. Tabs are right out.
More information about the Python-3000