[Python-ideas] Allow "assigning" to Ellipse to discard values.

Jonas Wielicki j.wielicki at sotecware.net
Wed Feb 11 15:38:23 CET 2015


On 10.02.2015 22:01, Spencer Brown wrote:
> Basically, in any location where a variable name is provided for assignment (tuple unpacking, for loops, function parameters, etc) a variable name can be replaced by '...' to indicate that that value will not be used. This would be syntactically equivalent to del-ing the variable immediately after, except that the assignment never needs to be done.
> 
> Examples:
>>>> tup =  ('val1', 'val2', (123, 456, 789))
>>>> name, ..., (..., value, ...) = tup
> instead of:
>>>> name = tup[0]
>>>> value = tup[2][1]
> This shows slightly more clearly what format the tuple will be in, and provides some additional error-checking - the unpack will fail if the tuple is a different size or format.

I don’t like that syntax at all. With _ it is much more readable. In
that context, ... rather looks like what *_ would do: Leaving out many
elements (even though that is not possible in python currently, at least
not in (*_, foo, *_); that only makes things worse).

This may be arbitrarily confusing. As others have said, just use

>>> tup =  ('val1', 'val2', (123, 456, 789))
>>> name, _, (_, value, _) = tup



regards,
jwi




More information about the Python-ideas mailing list