News for hackers. Stuff that matters.
Re:Namedtuple in a Post-Dataclasses World by Spivak on Wednesday July 21, 2021 @04:46PM (#27911950)
I feel like none of the sibling answers actually answer your question which is "absolutely nothing." The function namedtuple is code generator that constructs a class definition and then eval()'s it.

The reason you reach for it is because it's tedious to write the same methods over and over to get things like a nice repr, methods covert between dicts, or pickling support.

The source from Python 3.6 is much more readable than 3.9 so I recommend reading that if you want to see how it works.

https://github.com/python/cpython/blob/3.6/Lib/collections/_...

There are no comments on this comment yet.