First time writing a class here and I need a little help.
I've been trying to write a class in which the first takes a tab-delimited csv file and outputs a list of dictionaries. Each of the keys in the dictionary is a column title in the csv.
So far, this is what my class looks like:
import csv class consolidate(object): def __init__(self, file): self.file = file def create_master_list(self): with(open(self,'rU')) as f: f_d = csv.DictReader(f, delimiter = '\t') m_l = [] for d in f_d: m_l.append(d) return m_l When I try to pass it a file, as follows:
c = consolidate() a = c.create_master_list('Abilities.txt') I get the following error:
TypeError: __init__() takes exactly 2 arguments (1 given) I know that what I want to pass a file argument to the create_master_list function, but I'm unsure what the right syntax to do this is.
I've tried self.file and file as arguments, and both do not work as well.
Thanks!