Caffeinated Coder
Book an appointment
Lesson 13 · Real programs

Working with files

Variables vanish when a program ends; files stay on disk. Step through a six-line program, files.py, that writes a two-item shopping list to shop.txt and reads it back. Watch open() hand you a file object, see the writes wait in a buffer until with closes the file, read the file one line at a time, and meet the error you get when a file is missing.

12 min10 steps5 questionsIntermediate
Fig 13 · Interactive
Loading figure…
or ← →

Quiz Unlocks after the last step.