How to create a csv file using python's csv module? -


how can use python create csv file named ted.csv instance using csv module:

import csv open('ted.csv', 'wb') csvfile:     spamwriter = csv.writer(csvfile, delimiter=',') 

gives me error

module has no attribute reader

a simple example seen here. import csv module. open csv file want write to. when writerow, write data in array delimited character specified in delimeter argument csv.writer.

import csv open('ted.csv', 'w') csvfile:     spamwriter = csv.writer(csvfile, delimiter=',')     spamwriter.writerow(['spam'] * 5 + ['baked beans'])     spamwriter.writerow(['spam', 'lovely spam', 'wonderful spam']) 

this give ted.csv file following content in file

spam,spam,spam,spam,spam,baked beans spam,lovely spam,wonderful spam 

Comments