[Python-ideas] Generator unpacking
Jared Grubb
jared.grubb at gmail.com
Sun Feb 14 19:47:20 EST 2016
> On Feb 14, 2016, at 10:57, Georg Brandl <g.brandl at gmx.net> wrote:
>
> 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.
That looks harder to read than what you can currently do:
a, _, b, _ = some_function()
But I do like the asterisk+ellipsis.
>> 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
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160214/eae6cab5/attachment.html>
More information about the Python-ideas
mailing list