tags:

views:

578

answers:

3

hi, I am trying to add new row to my old csv file. Basically it get update each time when I run the python script. Right now I am storing the old csv rows values in list and then deleting the csv file and creating it again with the new list value.

Wanted to know is there any better ways of doing it.

Thanks

+3  A: 
fd = open('my.csv','wa')
fd.write(myCsvRow)
fd.close()

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

inkedmn
I triedfp = open(csv_filepathwithname, 'wa') writer = csv.writer(fp) somelist = [ 3,56,3,6,56] writer.writerow((somelist))but only the last row get append in the file.
laspal
Should not be "wa". Should be "a".
S.Lott
A: 

Are you opening the file with mode of 'a' instead of 'w'?

gnibbler
A: 

Still can solve the problem

Thanks

laspal
Finally solved. Sorry for all the problems.Using 'a' instead of 'wa'Thanks
laspal
This is not a very good answer. Please delete this. It makes almost no sense. @laspal: You can answer your own question. But commenting on your own answer is silly. Fix your answer so it's right. Don't comment on your answer. Please delete the comment and fix the answer.
S.Lott