On Fri, Jul 28, 2017 at 7:22 AM, Pavol Lisy <[email protected]> wrote: > On 7/26/17, Steven D'Aprano <[email protected]> wrote: > > [...] > >> But this has a hidden landmine. If *any* module happens to use ntuple >> with the same field names as you, but in a different order, you will >> have mysterious bugs: >> >> x, y, z = spam >> >> You expect x=2, y=1, z=0 because that's the way you defined the field >> order, but unknown to you some other module got in first and defined it >> as [z, y, x] and so your code will silently do the wrong thing. > > 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. ChrisA _______________________________________________ Python-ideas mailing list [email protected] https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
