how to add a row in csv file using python code example

Example 1: python csv write add new line

with open('output.csv', 'w', newline='\n', encoding='utf-8') as f:
    writer = csv.writer(f)
    ...

Example 2: 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 3: append to csv python

with open('document.csv','a') as fd:
    fd.write(myCsvRow)

Example 4: python csv add row

import csv   

fields=['first','second','third']

with open(r'name', 'a') as f:
    writer = csv.writer(f)
    writer.writerow(fields)