On Mon, 14 Mar 2022 at 22:21, Greg Ewing <greg.ew...@canterbury.ac.nz> wrote:
>
> On 15/03/22 6:14 am, wfdc via Python-ideas wrote:
> > The whole *point* is that namedtuples let you use *named fields* rather 
> > than indices. That's the point. That's the purpose.
>
> I would say the point of namedtuple is to let you use either field
> names or indices, whichever makes the most sense for what you're
> doing at the time. Otherwise why not just use a regular class?

As I understood it, one motivation for the introduction of namedtuple
was that where you had an API that returned a tuple you could change
that to return a namedtuple without breaking backwards compatibility.
Then older code expecting a tuple could still use tuple-ish idioms
like unpacking, slicing or indexing but newer code could use names to
access the elements.

--
Oscar
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/5TEZKOONYRJUHJVLD55XRBEBYWZEZARV/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to