namedtuples_renamecolumn

emlib.misc.namedtuples_renamecolumn(namedtuples, oldname, newname, classname=None)[source]

Rename the column of a seq of namedtuples

Parameters:
  • namedtuples – a list of namedtuples

  • oldname – the name of the column which will be modified

  • newname – the new name of the column

  • classname – the name of the new namedtuple class

Returns:

the new namedtuples with the renamed column

>>> from collections import namedtuple
>>> Person = namedtuple("Person", "firstname familyname")
>>> people = [Person("John", "Smith"), Person("Amy", "Adams")]
>>> people2 = namedtuples_renamecolumn(people, "firstname", "first_name")
>>> people2[0]._fields
('first_name', 'familyname')