[Python-ideas] Generator unpacking
Georg Brandl
g.brandl at gmx.net
Sun Feb 14 13:57:09 EST 2016
On 02/14/2016 08:43 AM, Nick Coghlan wrote:
> On 14 February 2016 at 07:40, Greg Ewing
> <greg.ewing at canterbury.ac.nz
> <mailto:greg.ewing at canterbury.ac.nz>> wrote:
>
>
> Another possibility is
>
> a, b, ... = value
>
>
> Now, *that* spelling to turn off the "implicit peek" behaviour in iterable
> unpacking I quite like.
>
> arg_iter = iter(args)
> command, ... = arg_iter
> run_command(command, arg_iter)
>
Assigning to Ellipsis? Interesting idea, but I'd probably go a bit further
in the similarity to star-assignment:
a, b, *... = value
Ellipsis could then be a general "throw-away" lvalue. This would make it
possible to say
a, ..., b, ... = some_function()
i.e. skip exactly one item in unpacking.
> Although again, the main downside would be that "..." here means something
> rather different from what it means as a subscript element.
Keep in mind that Ellipsis is also a legal rvalue anywhere else. I.e.
this would be legal (and a no-op):
... = ...
But thinking about it, this is also legal at the moment:
[] = []
Interestingly, this raises:
() = ()
cheers,
Georg
More information about the Python-ideas
mailing list