最佳答案
Assume I have a csv.DictReader
object and I want to write it out as a CSV file. How can I do this?
I know that I can write the rows of data like this:
dr = csv.DictReader(open(f), delimiter='\t')
# process my dr object
# ...
# write out object
output = csv.DictWriter(open(f2, 'w'), delimiter='\t')
for item in dr:
output.writerow(item)
But how can I include the fieldnames?