I am writing a dictionary in a CSV file using this:
self.idSelf += 1
self.tweet["tweet"] = tweetText
self.tweet["id"] = id
self.tweet["sequence"] = self.idSelf
self.tweet["created_at"] = created_at
with open('#KXIPvMI-2018-05-04.csv', 'a') as csv_file:
writer = csv.writer(csv_file)
a = [self.tweet]
print a[0]['tweet']
writer.writerow([self.tweet])
While reading this file, I get a list of length = 1. I get the whole dictionary that I saved by writing row = info[0]. But when I get the type(row), it is str and not the dictionary. Why is that and how can I get the dictionary?
csv.DictWriter.csv.DictWriterdocumentation.writer = csv.DictWriter(csvfile, self.fieldnames=fieldnames)but I am getting an error:writer = csv.DictWriter(csv_file, fieldNames = self.fieldNames) TypeError: __init__() takes at least 3 arguments (2 given)