Lazo Lab Sign up

Python Projects & Skills / Files and data

Lesson 11 of 28

CSV files

CSV files are spreadsheets as plain text. The csv module reads each row as a list or, with DictReader, a dictionary.

Key points

  • csv.reader for lists
  • csv.DictReader for dictionaries
  • Open with newline=''
import csv
with open("scores.csv", newline="") as f:
    for row in csv.DictReader(f):
        print(row["name"], row["score"])
Watch a video on thisOpens YouTube search results for “CSV files” in a new tab

Quiz · +10 XP

Which reader gives each row as a dictionary?

Log in to save progress and earn XP.