Unit 09 · overview

Unit 9: Files & Persistent Data

Memory disappears when a process ends. Files let a program leave state behind.

That sounds simple until the file is missing, the path is wrong, the JSON is malformed, the CSV columns change, or the program writes data successfully but loads a different file than you expected.

Two kinds of truth

During execution, your program has runtime state. On disk, files contain persistent state.

Those can disagree.

runtime object -> serialization/write -> bytes/text on disk
bytes/text on disk -> read/parse -> new runtime object

This Unit makes that boundary visible with paths, text files, CSV, JSON, encoding, context managers, validation, and failure handling.

You will inspect the file itself instead of trusting a “Saved!” message. You will restart the program and prove that the state can be reconstructed from disk. You will also test at least one missing, malformed, or unexpected-data condition.

Persistence proof

Keep one before/after record showing:

  1. runtime data before saving;
  2. the exact file/path created;
  3. a piece of the serialized content;
  4. a fresh program run that reloads it; and
  5. the recovered runtime value.

That chain proves persistence. A variable still existing in the same process does not.