Why does Python not support a record type natively? It\'s a matter of having a mutable version of namedtuple.
I could use namedtuple._replace
. But I nee
This answer duplicates another one.
There is a mutable alternative to collections.namedtuple
- recordclass.
It has same API and memory footprint as namedtuple
(actually it also faster). It support assignments. For example:
from recordclass import recordclass
Point = recordclass('Point', 'x y')
>>> p = Point(1, 2)
>>> p
Point(x=1, y=2)
>>> print(p.x, p.y)
1 2
>>> p.x += 2; p.y += 3; print(p)
Point(x=3, y=5)
There is more complete example (it also include performance comparisons).