0%

Python Outside the Browser · practice

A File Outlives the Run

A REPL name belongs to one interpreter session. A saved .py file is different: it keeps , the instructions another run can read later.

Keep three nouns separate:

  • the file waits as saved instructions;

  • an interpreter reads and carries out those instructions;

  • a run uses temporary memory while the instructions are carried out. That is the learner-level process model from the previous lesson.

The site editor starts with familiar syntax:

runs_in_this_execution = 0
runs_in_this_execution += 1

print()

Complete the print line so the program displays:

This run counts to 1.

Use an that reads runs_in_this_execution; do not type the answer as a fixed sentence. Run the saved source twice. Each execution displays the same line because the first reconstructs the name from zero each time. Changing a in one execution’s memory does not rewrite the saved source.

This is the whole idea the chapter exists for, so it is worth saying once more in plain words. The file remembers. The run does not.

One version note before we move on: Python Land runs this course on Python 3.13, and the project you download in Chapter 4 works on Python 3.10 or newer. This tiny program is happy on any of them.

Next, Chapter 2, The , Enough of It, teaches , working directories, paths, and finally how python report.py connects an interpreter to a file. Chapter 3 owns isolated environments and packages. Chapter 4 owns download, editor setup, local execution, and local checking. This lesson does not verify any of those later steps.

You run the saved program twice and it prints This run counts to 1. both times. Why not 2 the second time?

What is the difference between the file and the run?

Stuck on the f-string? Ask Monty: “What is the difference between print(f"...{runs_in_this_execution}") and typing the number directly?” That difference is the whole point of this exercise.

Task

Complete the final print call with an that reads runs_in_this_execution. Run the saved source twice and observe the same exact line each time: This run counts to 1.