Module 12
Exporting CSV
Saving results to a file.
Saving your work
You can export your results to a CSV file so they can be opened in a spreadsheet or shared with others.
import csv
results = [{"id": "Tv01", "gc": 54.2}, {"id": "Tv02", "gc": 48.1}]
with open("output.csv", "w", newline="") as f:
writer = csv.DictWriter(f, fieldnames=["id", "gc"])
writer.writeheader()
writer.writerows(results)
print("Saved")Your task
Export CSV
- Write results to a CSV file.