append new row to old csv file python

laspal picture laspal · Mar 2, 2010 · Viewed 442k times · Source

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.

Wanted to know are there any better ways of doing this.

Answer

brettkelly picture brettkelly · Mar 2, 2010
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.