janecs
janecs

Reputation: 209

python adding a title row to csv output file

I have a python script that gets data from a database and outputs a csv file. Now I'm trying to add a header row containing titles for each of the columns. What do I need to add so that it outputs an initial row ahead of the db output (I'm quite a newbie to python, so I got stuck in this part and couldn't find the info I needed)?

Thanks in advance!

Upvotes: 2

Views: 891

Answers (1)

nmichaels
nmichaels

Reputation: 50981

If you're using a DictWriter, you can just call writeheader.

Upvotes: 2

Related Questions