Packages and __init__.py
Organize modules into packages with proper directory structure.
What Is a Package?
A package is a directory that contains an __init__.py file and one or more modules. Python treats any such directory as a package you can import from.
mypackage/
__init__.py
utils.py
math_helpers.pyThe __init__.py File
__init__.py runs when the package is imported. It can be empty or expose selected names to callers.
# mypackage/__init__.py
from .utils import helper
from .math_helpers import addAll lessons in this course
- Creating and Importing Modules
- The Python Standard Library
- Packages and __init__.py
- Installing Packages with pip