How to append a new row to an old CSV file in Python?

csv, python, writer

Solution

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

Opening a file with the `'a'` parameter allows you to append to the end of the file instead of simply overwriting the existing content. Try that.

Problem

I am trying to add a new row to my old CSV file. Basically, it gets updated each time I run the Python script. Right now I am storing the old CSV rows values in a list and then deleting the CSV file and creating it again with the new list value. I wanted to know are there any better ways of doing this.

Original source

Related problems