On January 21th at 14:15 UTC , progression through exercises will be unavailable for 10 minutes due to a planned maintenance break.
Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
12. Summary


Good job! It's time to wrap things up.

  1. To write data into CSV files, you can use the following template code (using lists):
    with open('filename.csv', mode='w', newline='') as csv_file:
      csv_writer = csv.writer(csv_file)
      for row in data_to_save:
  2. If you prefer dictionaries, you can use a DictWriter instead:
    with open('books.csv', mode='w', newline='') as csv_file:
      csv_writer = csv.DictWriter(csv_file, fieldnames=['field1','field2'])
      for row in data_to_save:
    Use csv_writer.writeheader() to insert the header row.
  3. Instead of a for loop, you can use the writerows() method to insert multiple rows.
  4. You can specify additional parameters such as delimiter, quotechar, and quoting. For example:
    csv.writer(csv_file, fieldnames=['Author','Title','Pages'], quotechar="'", quoting=csv.QUOTE_ALL)

Excellent! How about taking on a challenge now?


Click Next exercise to continue.