[Python-ideas] namedtuple literals [Was: RE a new namedtuple]
Pavol Lisy
pavol.lisy at gmail.com
Thu Jul 27 17:22:09 EDT 2017
On 7/26/17, Steven D'Aprano <steve at pearwood.info> 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)
More information about the Python-ideas
mailing list