All posts
postMay 21, 2026

Python: read a CSV file the right way

#python#csv#file-io
python
import csv

with open("users.csv") as f:
    reader = csv.DictReader(f)
    for row in reader:
        print(row["email"], row["country"])

# row is a dict: {"email": ..., "country": ..., ...}

Reading CSV files is the single most common task in data engineering. Beginners reach for sentence.split(",") and immediately hit problems: commas inside quoted fields, escaped quotes, line breaks within cells.

Pythons built-in csv module handles all of this for you. csv.DictReader returns each row as a dictionary keyed by column name, which is almost always what you want. Use it from day one and skip a class of bugs entirely.