[Python-ideas] namedtuple literals [Was: RE a new namedtuple]
אלעזר
elazarg at gmail.com
Thu Jul 27 18:14:47 EDT 2017
On Fri, Jul 28, 2017 at 12:51 AM Chris Angelico <rosuav at gmail.com> wrote:
> On Fri, Jul 28, 2017 at 7:22 AM, Pavol Lisy <pavol.lisy at gmail.com> wrote:
>
> > We have:
> > from module import x, y, z # where order is not important
> >
> > Could we have something similar with ntuple (SimpleNamespace, ...)?
> >
> > maybe:
> > for x, y, z from spam:
> > print(x, y, z)
>
> What you're asking for is something like JavaScript's "object
> destructuring" syntax. It would sometimes be cool, but I haven't ever
> really yearned for it in Python. But you'd need to decide whether you
> want attributes (spam.x, spam.y) or items (spam["x"], spam["y"]). Both
> would be useful at different times.
>
>
Maybe something like
{x, y} = point
Or with aliasing
{x as dx, y as dy} = point
Then you can have
{'x' as x, 'y' as y, **} = spam
Elazar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170727/d2e37299/attachment-0001.html>
More information about the Python-ideas
mailing list