Imports and the Module Search

Scenario: Two scripts copy the same calculation and drift apart.

New words, in plain English

Prefer import mathutils and explicit mathutils.add. from x import y can be concise; wildcard imports hide origins. Python searches built-ins, the project, and configured package locations.

Analogy: A Python program is like a clear set of instructions for a careful helper: names label things, indentation groups steps, and errors explain where the helper became confused.

A small, real example

# mathutils.py
def add(a, b):
    return a + b

# main.py
import mathutils
print(mathutils.add(2, 3))
Tip: Avoid naming your file json.py, csv.py, or another standard module name.
Goal: Practice this idea in the py-modules-import challenge at /labs/python. Fix the broken program, run it yourself, then use check to prove the real end state.