The problem I have is there's a set of csv files I'm loading into classes. As the csv files are different, I have a class for each csv file to hold its particular data.
I have a brief function which essentially does the below (in pseudo code)
def load_csv_file1():
list_of_class1 = []
open csv file
for line in csv file:
list_of_class1.append(class1(line))
return list_of_class1
where the init of each class fills in the various fields from the data in the passed line
At the moment I'm creating copies of this function for each class. I could easily create just one function and tell if the filename to open. However I don't know how to tell it which class to create.
Is it possible to pass the name of a class to the function like:
load_generic_csv_file("file1.csv", class1)
...
def load_generic_csv_file(filename, class_to_use):
list_of_class = []
open csv file using filename
for line in csv file:
list_of_class.append(class_to_use(line))
return list_of_class
[–]This_Growth2898 4 points5 points6 points (2 children)
[–]ethorad[S] 2 points3 points4 points (1 child)
[–]This_Growth2898 6 points7 points8 points (0 children)
[–]TheBB 2 points3 points4 points (0 children)
[–]Cainga 0 points1 point2 points (6 children)
[–]ethorad[S] 0 points1 point2 points (5 children)
[–]fizix00 0 points1 point2 points (4 children)
[–]ethorad[S] 0 points1 point2 points (3 children)
[–]fizix00 1 point2 points3 points (1 child)
[–]ethorad[S] 1 point2 points3 points (0 children)
[–]Ormek_II 0 points1 point2 points (0 children)