Pythonification of the asterisk-based collection packing/unpacking syntax

Eelco hoogendoorn.eelco at gmail.com
Thu Dec 29 09:20:11 EST 2011


On Dec 29, 2:23 pm, Steven D'Aprano <steve
+comp.lang.pyt... at pearwood.info> wrote:
> On Thu, 29 Dec 2011 03:55:14 -0800, Eelco wrote:
> > I would argue that the use of single special characters to signal a
> > relatively complex and uncommon construct is exactly what I am trying to
> > avoid with this proposal.
>
> This would be the proposal to change the existing
>
>     head, *tail = sequence
>
> to your proposed:
>
>     head, tail:: = ::sequence
>
> (when happy with the default list for tail), or
>
>     head, tail::tuple = ::sequence
>
> to avoid an explicit call to "tail = tuple(tail)" after the unpacking.
>
> Either way, with or without an explicit type declaration on the left hand
> side, you are increasing the number of punctuation characters from one to
> four. If your aim is to minimize the number of punctuation characters,
> you're doing it wrong.
>
> --
> Steven

The goal is not to minimize the number of (special) characters to
type. To goal is to minimize the number of special characters which
are hard to interpret at a glance. I would prefer : over ::, but both
are a single special character construct. Adding those characters once
more on the rhs is similarly, not an increase in the number of
concepts employed; merely a more explicit form of the same construct.

And besides, I dont much like 'head, tail:: = ::sequence'. I threw
that out there to appease the terseness advocates, but to me it
largely defeats the purpose, because indeed it is hardly any different
from the original. I like the explicit mentioning of the collection
type to be constructed; that is what really brings it more towards
'for line in file' explicit obviousness to my mind.



More information about the Python-list mailing list