[Python-ideas] Anonymous namedtuples
Peter Otten
__peter__ at web.de
Tue Apr 19 06:13:28 EDT 2016
Joseph Martinot-Lagarde wrote:
> Proposal
> ========
>
> So I thought about a new (ok, maybe it has been proposed before but I
> couldn't find it) syntax for anonymous namedtuples (I put the prints as
> comments, otherwise gmane is complainig about top-posting):
>
> my_point = (x=12, y=16)
> # (x=12, y=16)
> my_point[0]
> # 12
> my_point.y
> # 16
> type(my_point)
> # <class 'anonymousnamedtuple'>
>
> It's just a tuple, but with names. Parenthesis would be mandatory because
> `my_point = x = 12, y = 16` wouldn't work. Single elements anonymouns
> namedtuples would require a trailing comma, similarely to tuples.
That would be a great addition!
The parens could be optional for return values
return x=1, y=2
More information about the Python-ideas
mailing list