A subpackage is a package nested inside another package’s directory. It helps organize a large library across related modules without putting everything in one file or at one level. section 18.3 section 18.7
A nested package
In `mathproj/comp/numeric/n1.py`, `numeric` is a subpackage of `comp`, which is itself a subpackage of `mathproj`. Each package directory has an `__init__.py` file; an empty one is often enough. The `n1.py` module imports from both `mathproj` and `mathproj.comp`. section 18.3 section 18.3.1
Import the nested module you need: `import mathproj.comp.numeric.n1`. Importing `mathproj` alone does not load all its subpackages and modules. On the nested import, Python loads `mathproj.comp` and then `mathproj.comp.numeric` before `n1`, executing each package’s `__init__.py` the first time it loads. section 18.3.3
import mathproj.comp.numeric.n1 Hello from mathproj.comp init Hello from numeric init mathproj.comp.numeric.n1.g() version is 1.03 Called function h in module n2
The import prints messages from both subpackage initializers; calling `mathproj.comp.numeric.n1.g()` then uses code from the nested module. section 18.3.3
Subpackages need an explicit import, either in your code or in a package’s `__init__.py`. Reserve deeper nesting for libraries complex enough to justify it; one or two levels is usually plenty. section 18.7
