python create csv and add row code example
Example 1: append record in csv
import csv
fields=['first','second','third']
with open(r'name', 'a') as f:
writer = csv.writer(f)
writer.writerow(fields)
Example 2: writerows to existing csv python
import sys
import os
import csv
listOfLines= [['[email protected]', '[email protected]', '[email protected]', '[email protected]', '[email protected]', '[email protected]']]
def write_to_csv(list_of_emails):
with open('emails.csv', 'w', newline='') as csvfile:
writer = csv.writer(csvfile, delimiter = ',')
writer.writerows(list_of_emails)
write_to_csv(listOfLines)