且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

新行追加到老csv文件蟒蛇

更新时间:2023-12-06 15:57:52

  FD =开放('document.csv','A')
fd.write(myCsvRow)
fd.close()

打开文件的'A'参数,可以附加到文件末尾,而不是简单地覆盖现有的内容。试试。

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.

fd = open('document.csv','a')
fd.write(myCsvRow)
fd.close()

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.