Keeping a list of records with named fields that can be updated

Albert-Jan Roskam sjeik_appie at hotmail.com
Sat Dec 17 14:45:18 EST 2022


   On Dec 15, 2022 10:21, Peter Otten <__peter__ at web.de> wrote:

     >>> from collections import namedtuple
     >>> Row = namedtuple("Row", "foo bar baz")
     >>> row = Row(1, 2, 3)
     >>> row._replace(bar=42)
     Row(foo=1, bar=42, baz=3)

   ====
   Ahh, I always thought these are undocumented methods, but: "In addition to
   the methods inherited from tuples, named tuples support three additional
   methods and two attributes. To prevent conflicts with field names, the
   method and attribute names start with an underscore."
   https://docs.python.org/3/library/collections.html#collections.somenamedtuple._make


More information about the Python-list mailing list