Category: csv

Problem

Write rows from dicts to CSV.

Solution

  writer = csv.DictWriter(f, fieldnames=fields)
writer.writeheader(); writer.writerows(rows)
  

Notes

  • Adapt variable names and paths to your project
  • Add error handling for production use
  • See related chapters in the Learning Path