[Python-ideas] Generator unpacking
Sven R. Kunze
srkunze at mail.de
Tue Feb 16 05:11:42 EST 2016
On 16.02.2016 01:11, Andrew Barnert via Python-ideas wrote:
> I see this more often written in tuple-ish form:
>
> index, value = struct.unpack_from('!HH', buf, off)
> namelen, = struct.unpack_from('!H', buf, off+4)
>
> Somehow, that feels more natural and pythonic than using [index, value] and [namelen], despite the fact that without the brackets it's easy to miss the trailing comma and end up with (16,) instead of 16 as your length and a confusing TypeError a few lines down.
You are right. It seems to me that without the parentheses it's not
regarded a tuple but a special feature syntax; so all the known
peculiarities of tuples aren't recognized properly.
Best,
Sven
More information about the Python-ideas
mailing list