CoursePython from Scratch to Intermediate · Module 8: Errors, Files and Debugging · part 55 of 75
Part 55 · Module 8: Errors, Files and Debugging

Lesson 3: Tables and records in CSV and JSON files

17 min read·14 Oct 2026
Module 8 · Lesson 3 · About 50 minutes · Needs: Module 8 Lessons 1 and 2 (try and except, with open(...), encoding="utf-8"), Module 7 (datetime, pathlib), Module 5 (dictionaries, comprehensions)

The situation

"The real records are the files," Amira says. "Read those, and give me answers as files I can open." Books and loans are in books.csv and loans.csv, saved from her spreadsheet; members are in members.json, because each has a list of favourite genres.

This lesson reads all three, follows Jonah's loan L04 (Frankenstein, still out) the whole way, writes files back, and checks every row instead of trusting it.

FILES ON DISK IN PYTHON FILES OUT books.csv loans.csv members.json dictionaries checked, converted overdue.json 580p owed problem list every bad row
The lesson's path: the shelf's three files (blue, your system) become checked dictionaries in Python, then go back out as answer files (green) and a list of bad rows (red).

The rest of this part opens with an account

Signing up is free and takes one email. Nothing to pay, and nothing renews.