Reading and Writing Files · capstone
Capstone project: Run the Durable Journal
The program is complete. This final lesson changes the surface, not the code: the panel below is a Bash session looking at the same saved chapter workspace.
Start by proving where you are and running the entry file twice:
pwd
python reading_log.py
python reading_log.py
Each successful run should print:
Wrote reading_report.txt and recorded 4 books.
Running it twice is not the interesting part. What the two runs leave behind is.
Inspect the durable result
cat reading_report.txt
cat reading_history.txt
The report should contain one current snapshot:
Reading report
==============
Books: 4
- The Left Hand of Darkness
- Cien años de soledad
- Piranesi
- Convenience Store Woman
The history should contain at least two complete Recorded 4 books. lines. If an earlier editor Run already created a record, it stays too. That is correct: the file exists to preserve successful runs, and this lesson does not pretend it began empty.
If the report contains two headings, revisit write_report: the snapshot was appended. If history contains only one line after two more runs, revisit append_history: earlier records were replaced. If Python cannot find data/books.txt, compare pwd with the project root before editing any path.
What you actually built
Press Check my work when the visible files agree.
Then look at the folder as a whole, because this is the first time in the course that all four pieces exist at once. There is a program, the input it reads, the current answer it produced, and a record of every time it ran. The Python process has exited. The
That is what “durable” means, and it is the difference between a program that computes something and a program that leaves something behind. Every project in the rest of this course is a variation on this shape.