Lesson 2: Reading and writing files that outlast your program
16 min read·14 Oct 2026
Module 8 · Lesson 2 · About 45 minutes · Needs: Modules 1 to 7 (strings, loops, functions,pathlib.Path) and Lesson 1 (tryandexcept)
The situation
Amira has Tom's typed-up notebook. "Can your program read it, and write down what is wrong with it?" Until now every value lived in a variable, and vanished when the session ended. A file stays on the disk after your program stops, and another program or person can open it.
This lesson follows one file, data/tom_notebook.txt, Tom's twelve lines from September: written, read back, and its faults recorded in a second file.