namedtuples_renamecolumn¶
- emlib.misc.namedtuples_renamecolumn(namedtuples, oldname, newname, classname='')[source]¶
Rename the column of a seq of namedtuples
- Parameters:
namedtuples (
list) – a list of namedtuplesoldname (
str) – the name of the column which will be modifiednewname (
str) – the new name of the columnclassname – the name of the new namedtuple class
- Return type:
list- 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')