A namespace associates names with objects while separating those names from other naming contexts. In Python, each module has its own namespace, so collaborators can use similar variable or function names without collisions. Modules also provide a place to define reusable data structures, functions, and classes. section 9.0
Importing through a module namespace
Use a qualified module name when you want the module namespace to remain explicit: import os The import statement defines a variable, os, that references the module; it does not import a filename such as "os.py". Python searches directories in sys.path for a matching module. Alternatively, from os import sep defines sep directly in the current namespace, while import os keeps access qualified as os.sep. section 9.1
Table 9.1 What you need to know
|
Concept
|
What is it?
|
Example
|
To learn more
|
|---|---|---|---|
import
|
Statement for importing modules
|
import os
|
|
from X import Y
|
Imports module X, but only defines Y as a global variable
|
from os import sep
|
|
importlib.reload
|
Re-imports an already loaded module, typically to update definitions during development
|
importlib.reload(mymod)
|
|
pip
|
Command-line program for installing packages from PyPI
|
pip install packagename
|
|
Decimal
|
Class that accurately handles floating-point numbers
|
from decimal import Decimal
|
Use the reference table to compare import forms and related module tools, including import, from X import Y, importlib.reload, and pip. section 9.1



















