Answer the question
In order to leave comments, you need to log in
How to create a namedtuple with a dynamic number of fields?
Good day
An example from the manual of the collections module:
EmployeeRecord = namedtuple('EmployeeRecord', 'name, age, title, department, paygrade')
import csv
for emp in map(EmployeeRecord._make, csv.reader(open("employees.csv", "rb"))):
print emp.name, emp.title
Answer the question
In order to leave comments, you need to log in
If I understand the problem correctly stackoverflow.com/questions/15324644/how-do-i-add-...
If you know in advance what fields will definitely be and you are only interested in them, why not just create your own class with these parameters, __init__ of which will take these parameters as input in the right order, and *args - which will include everything else, which you can if you wish keep or ignore.
if you care about memory allocation use __slots__
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question