ehsan shirzadi
ehsan shirzadi

Reputation: 4859

Append rows to csv file

I want to add python list to a csv file with this code:

RESULTS = ['aa','bb','cc']
resultFile = open("c:\\temp\\output4.csv",'wb')
wr = csv.writer(resultFile, dialect='excel')
wr.writerows(RESULTS)
resultFile.flush()

but this code overwrites my previous file. how to enable appending?

Unfortunately I can't find any solution to do this using this way.

Upvotes: 0

Views: 113

Answers (1)

Martijn Pieters
Martijn Pieters

Reputation: 1121186

Open the file in append mode instead:

resultFile = open("c:\\temp\\output4.csv", 'ab')

Upvotes: 3

Related Questions