CoursePython from Scratch to Intermediate · Module 7: Modules, the Standard Library and Packages · part 46 of 75
Part 46 · Module 7: Modules, the Standard Library and Packages

Lesson 1: Modules and imports: the shelf rules in one file

16 min read·14 Oct 2026
Module 7 · Lesson 1 · About 45 minutes · Needs: Modules 1 to 6 (functions with def and return, docstrings, assert, %%writefile and !python from Module 1 Lesson 2)

The situation

Amira's next request is "Use real dates." First the shelf's code needs a home. late_fee lives in a notebook cell, and every new notebook types it out again, until one copy says 20 pence a day and another says 25.

This lesson moves the rules into one file, fees.py, that every notebook can borrow from. You will follow Ben's L13, 9 days late, which should cost 180 pence wherever it is asked. By the end the file sits in a folder called booknook: the start of the shelf's package.

BEFORE: COPIED AFTER: IMPORTED notebook 1 20p a day notebook 2 20p a day notebook 3 25p a day fees.py 20p a day notebook 1 notebook 2 notebook 3
Copied rules drift apart (red: one copy now says 25p); rules kept in one file and imported (green) give every notebook the same answer.

The rest of this part opens with an account

Signing up is free and takes one email. Nothing to pay, and nothing renews.