Header written as row in CSV Python
问题 I have the following code which I am using to create and add a new row to a csv file. def calcPrice(data): fieldnames = ["ReferenceID","clientName","Date","From","To","Rate","Price"] with open('rec2.csv', 'a') as csvfile: writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writeheader() writer.writerow(data) return However, it as the header as a new row as well. How can I prevent this? Here's a link to the gist with the whole code: https://gist.github.com/chriskinyua