Spring Deals - hours only!Up to 70% off on all courses and bundles.-Close
Introduction
Writing CSV files
Summary

Instruction

Good job! You can also provide additional parameters to csv.writer or csv.DictWriter and specify your own delimiter, quote character, or quoting style. For example:

with open('books.csv', mode='w', newline='') as csv_file:
  csv_writer = csv.DictWriter(csv_file, fieldnames=['Author', 'Title', 'Pages'], delimiter=';')
  for row in data_to_save:
    csv_writer.writerow(row)

On line 2, we added an optional parameter: delimiter=';'. As a result, our DictWriter will use semicolons to separate fields.

Exercise

Modify the template code so that it uses a semicolon as its delimiter.

Stuck? Here's a hint!

Add an optional delimiter parameter inside the csv.writer() function.