I have something like this, hardcoded:
class csv_row:
def __init__(self, name, time, more_stuff):
self.name = name
self.time = time
self.more_stuff = more_stuff
this class is the representation of a csv row. What I want to do is make this more generic, and grab the head of the csv file and use it to initialize it in the same way as this list. Something like so:
class csv_row:
def __init__(self, list_of_attrs):
for column in list_of_attrs:
# initialize a self.variable with the same name as the column
for example, the header for a csv is [name, time, something]
. The __init__
, when passed that, will initialize with:
self.name = name
self.time = time
self.something = something
How can this be done?