Reading and Writing Files

Recap and Feedback


In this part, your study log gained the ability to read and write files, which is a major milestone. The program you have at the end of this part is a genuinely persistent study log — the sessions you log are saved to disk and still there the next time you run the program. This is a big step up from the in-memory logs of the previous parts, which vanished as soon as the program ended.

This part introduced six big ideas. The local environment is the first: Python on your own machine, a code editor, a terminal, and the realisation that the working directory matters for every file your code touches. Reading files with with/open, the three read methods, and .split() for breaking lines into fields. Writing files, the danger of "w" versus "a", and the parallel of .join() to .split(). CSV as the canonical structured-text format, with csv.reader and csv.writer doing what hand-splitting and hand-joining could not. Multidimensional lists as the in-memory shape of tables, images, and game boards alike. Defensive programming as the discipline of validating data at the boundary and never silently swallowing problems.

A seventh idea, conceptual rather than mechanical, runs underneath all of these: all data lives in files, and what differs is the format. Pictures, sounds, videos, and saved games are not stored by some special mechanism; they are files, just like your CSV, with different conventions for how the bytes inside are arranged. Once you see this, a great deal of the computing world becomes legible.

The AI thread continued into its fourth skill: detecting plausible-but-wrong code. Reading tells you what a piece of code does, verifying tells you whether what it does is right, specifying tells you what to ask for in the first place, and detecting plausible-but-wrong tells you when “it runs” is not yet “it works”.

If this part has gone well, your study log is now genuinely persistent. Quit the program, restart it, and your sessions are still there. The data you log accumulates over days and weeks instead of vanishing the moment the program ends.

Recap Quiz

The recap quiz below is a short sequence of questions drawn from the main ideas of this part. Complete it before the feedback form.

Feedback

Next, please take a moment to reflect on your work in this part and provide feedback. Your input helps us improve the course materials.

A few questions worth thinking about as you reflect:

  1. Which chapter felt most straightforward?
  2. Which chapter still feels uncertain?
  3. Which file-handling edge case felt easiest to forget?
  4. How confident do you feel about checking AI-generated file code now?

Reflection and feedback

0 / 5 points

Consider the following statements and answer them based on your experiences from studying the materials and working on the assignments in this part. When answering the numeric statements, answer them so that value 1 means that you strongly disagree with the statement, and value 7 means that you strongly agree with the statement. Please be as honest as possible when answering. The feedback will be used to improve the course.

Looking Ahead

The next part returns to the data you have now started to accumulate. With sessions piling up across many runs, useful summaries become possible — not just the total minutes from this run, but totals across days, averages per subject, and streaks of consecutive days that show your study habits over time. Streaks in particular are only meaningful once you have data from multiple days, which only became possible in this part. The next part takes the persistent data and starts turning it into insight.

The AI thread continues with the fifth skill: comparing approaches. Most non-trivial programming problems have several reasonable solutions, and AI assistants are happy to produce one of them on the first request. The skill is recognising when there is more than one reasonable approach, eliciting the alternatives, and choosing among them deliberately — a level above “does this work” and “does it match my spec” into “is this the best of the available options.”