I can access elements of a named tuple by name as follows(*):
from collections import namedtuple Car = namedtuple(\'Car\', \'color mileage\') my_car = Car(\'
Another way of accessing them can be:
field_idx = my_car._fields.index(field) my_car[field_idx]
Extract index of the field and then use it to index the namedtuple.