"Use the source, Luke."
In this case, the module of interest is csv. We don't need the source here. Normally you would use it something like this:
csv.reader is initialized with a file object (what I learned to call a file "handle"), for which I typically use the variable name FH. But it will also work with data. So we can use it as shown here:We should have done
strip() on the data before split(), that will get rid of the extra element which is preserved as an empty list in the output. csv also has cool DictReader (and DictWriter) objects:I don't know a way to get
DictWriter to write the header. I guess you'd just do it separately with FH.write() when the file is first opened.