Imports and the Module Search
Scenario: Two scripts copy the same calculation and drift apart.
New words, in plain English
- Module - a Python file that can be imported
- Import - loading a module and binding names from it
- Namespace - the set of names available in one context
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 filejson.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 usecheckto prove the real end state.