Within the writers
directory, we have two scripts: csv_writer.py
and kml_writer.py
. Both of these writers are called depending on the types of data being processed in the metadata_parser.py
framework.
In this chapter, we will use the csv.DictWriter
instead of csv.Writer
just as in Chapter 5, Databases in Python, and Chapter 6, Extracting Artifacts from Binary Files. As a reminder, the difference is that the DictWriter
writes dictionary objects to a CSV file and the csv.Writer
function is more suited for writing lists.
The great thing about the csv.DictWriter
is that it requires an argument, fieldnames
, when creating the writer object. The fieldnames
argument should be a list that represents the desired order of columns in the output. In addition, all possible keys must be included in the fieldnames
list. If a key exists that is not contained in the list, an exception will be raised. On the other hand, if a key is not present in the...