csv.DictReader turns each record into a dictionary keyed by the header. This is clearer than positional indexes, but CSV remains text: types, encoding, and business rules must be explicit.
import csv
from pathlib import Path
origem = Path("clientes.csv")
with origem.open(encoding="utf-8", newline="") as arquivo:
leitor = csv.DictReader(arquivo)
for linha in leitor:
email = linha["email"].strip().lower()
ativo = linha["ativo"].strip().lower() == "sim"
print(email, ativo)
Open the file with newline="" as required by the module API and declare an encoding. Normalize only fields whose contract permits it. A missing column differs from an empty value, so validate fieldnames before processing a large batch.
Practical guidance
When writing, provide fieldnames to DictWriter, call writeheader(), and choose extrasaction deliberately. Set the delimiter, quote character, and dialect when the producer differs from the default. Do not blindly trust Sniffer; its result is heuristic. For user-opened spreadsheets, assess values beginning with =, +, -, or @ before export.
The TXT, CSV, and JSON file guide provides broader context. Use the pathlib guide for portable paths.
The official csv module documentation, accessed July 22, 2026, documents the API and its guarantees.