0Pricing
Python Academy · Lesson

Reading CSV with csv.reader

Read CSV files row by row and access columns by index.

Introduction

Python's csv module handles the complexities of CSV files: quoted fields, delimiters, and different line endings.

Opening a CSV File

with open('data.csv', newline='') as f: is the recommended way — newline='' lets the csv module handle line endings.
import csv, io
sample = 'name,age,city\nAlice,30,NYC\nBob,25,LA'
reader = csv.reader(io.StringIO(sample))
for row in reader:
    print(row)

All lessons in this course

  1. JSON Encoding and Decoding
  2. Handling Nested JSON Structures
  3. Reading CSV with csv.reader
  4. Writing CSV with csv.DictWriter
← Back to Python Academy