Feed on
Posts
Comments

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()


Bookmark and Share

if that was helpful ...

check out the other tips and tricks i've compiled on these pages. you might learn something else interesting!

Did I get this wrong? Let me know!

Trackback URI | Comments RSS