[Python-ideas] iterable.__unpack__ method
Greg Ewing
greg.ewing at canterbury.ac.nz
Tue Feb 26 00:37:48 CET 2013
João Bernardo wrote:
> Python already supports this odd syntax
>
> a, b, *[] = iterable
>
> because it interprets the [] not as an empty list, but as an empty "list
> of identifiers". Maybe it could be used for something useful.
No, because it already has a meaning: there must be no more
values left in the sequence.
> BTW, the del syntax has the same "problem"
>
> del a, b, (c,), [d], []
Or just
[] = iterable
The surprising thing is that a special case seems to be
made for ():
>>> () = []
File "<stdin>", line 1
SyntaxError: can't assign to ()
It's surprising because () and [] are otherwise completely
interchangeable for unpacking purposes.
--
Greg
More information about the Python-ideas
mailing list