when I need to add a new line to a .csv file, I tried this following scripts. file = 'test.csv'
with open(file,'r+',newline='') as csvfile:
row = ['hello,world\r\n']
csvfile.writelines(row)
then I check the .csv file, found out that the fist line has been changed.
hello,world
,1,33,1,1,2,0,107,107,52,5,20,12,19,32,52,23,4,42,0,5,3,3,4,3,0,1,0,1,1,2,0
339,558,69,428,1,15,1,0,0,0,0,1804,41,3,6,4,10,18,41,10,1,20,0,2,0,4,3,1,0,0,0,1,1,1,0
3379,411,3,465,1,0,0,0,3,0,0,1901,28,2,1,4,9,7,28,5,1,12,0,1,1,2,0,1,0,0,0,1,2,1,0
I wonder how can I add a new line in the beginning of a .csv file without changing the exist elements? Seek()? please help me, I really appreciate it!!!