I'm trying to write a list of dictionaries to a CSV and am having issues initializing csv.DictWriter()
. I've got:
fname = "Machine Detection Rate.csv"
with open(fname, "wb") as f:
fieldNames = ["Number of Packets", "Number of Machines"]
writer = csv.DictWriter(f, fieldNames=fieldNames, restval="", dialect="excel",)
writer.writeheader()
for line in machineCounter:
print "Got Here!"
writer.writerow(line)
The error I get is:
TypeError: __init__() takes at least 3 arguments (4 given)
I've tried various permutations of arguments, but don't seem to be able to get it to run. I also don't seem to be able to find anyone else who's had the problem. The only arguments I haven't tried specifying are *args
and **kwds
. I'm a noob still and despite reading, I don't understand how they work in this situation. Any ideas?
Edit: in the final for
loop I had writer.writerows()
which did not output the all the dicts in the list. Changed to writer.writerow()
.