In Python, the
csv module implements classes to read and write tabular data in CSV format. It has a class
DictWriter which operates like a regular writer but maps a dictionary onto output rows. The keys of the dictionary are column names while values are actual data.
csv.DictWriter constructor takes two arguments. The first is the open file handler that the CSV is being written to. The second named parameter,
fieldnames, is a list of field names that the CSV is going to handle.