A namespace maps names to objects. Assigning `x = 1` binds `x` to `1` in a namespace. Each module has its own namespace, so two modules can define `reverse` without a name clash: use `mymodule.reverse` or `othermodule.reverse` to choose one. section 10.7 section 10.1
Python looks for an unqualified name in the local namespace, then the global namespace, then the built-in namespace. If none contains it, Python raises `NameError`. At the top level of a module, script, or interactive session, local and global are the same namespace; assignments, function definitions, and imports add bindings there. section 10.7
A function call creates a local namespace for its parameters and variables. The function's global namespace belongs to where it was defined—not where it was called. A method follows the same direct local–global–built-in lookup; instance, class, and superclass names are instead reached through `self`. section 10.7 section 15.11
Inspect a function call
In `scopetest.py`, `v = 6` is a module-level binding. Inside `f(x)`, the assignment `y = x` creates a local binding, while `w = v` reads the module-level name. After `import scopetest`, calling `scopetest.f(2)` shows `x` on entry and `x`, `y`, and `w` on exit; its global listing contains the module's `v` and `f`, not the caller's names. section 10.7
Use these checks when a name is missing or unexpected:
- Call `dir()` to list names in the current global namespace; pass a module or type to inspect its members. section 2.4
- Call `globals()` and `locals()` to inspect bindings. At the top level they show the same bindings; inside a function, `locals()` shows its parameters and local variables. section 10.7
- Account for session state: deleting an imported module name makes later use raise `NameError`, and earlier imports can affect package examples. Restart the session when a clean namespace is needed. section 10.7 section 18.3



















