CSV Files

csv.reader(csvfile, dialect=’excel’, *fmtparams*)

If csvfile is a file object, it should be opened with newline=''.

A short usage example:

1
2
3
4
5
import csv
with open('eggs.csv', newline='') as csvfile:
spamreader = csv.reader(csvfile, delimiter=' ', quotechar='|')
for row in spamreader:
print(', '.join(row))

csv.writer(csvfile, dialect=’excel’, *fmtparams*)

If csvfile is a file object, it should be opened withnewline=''

1
2
3
4
5
6
import csv
with open('eggs.csv', 'w', newline='') as csvfile:
spamwriter = csv.writer(csvfile, delimiter=' ',
quotechar='|', quoting=csv.QUOTE_MINIMAL)
spamwriter.writerow(['Spam'] * 5 + ['Baked Beans'])
spamwriter.writerow(['Spam', 'Lovely Spam', 'Wonderful Spam'])