use csv to write out data in python
March 1st, 2012 by Lawrence David
the csv module is a helpful module for writing out data in python.
here’s how to write out data:
import csv
….
color_l = ['red','green','blue']
text_l = ['roses','turtles','water']
color_f = open(foo.bar,’w')
header_l=['text','color']
csv_o = csv.DictWriter(color_f,delimiter=’;',fieldnames=header_l)
csv_o.writeheader()
row_l = [{'text':a,'color':b} for a,b in zip(text_l,color_l)]
csv_o.writerows(row_l)
color_f.close()
