Reputation: 1193
The docs say: Packages are a way of structuring Python’s module namespace by using “dotted module names”. For example, the module name A.B designates a submodule named B in a package named A.
A package is defined in the docs a dir with some either subdirs or files. Those subdirs would be subpackages, following this convention. A submodule then would be a module in the subdir, or the subpackage?
Would it be more clear to say module name A.B designates a module named B in a package named A?
And suppose dir A has a subdir C which contains file D, then one would say D, fully A.C.D, is a submodue of A?
Upvotes: 1
Views: 242
Reputation: 36239
From the glossary on the term module:
An object that serves as an organizational unit of Python code. Modules have a namespace containing arbitrary Python objects. Modules are loaded into Python by the process of importing.
... and on the term package:
A Python module which can contain submodules or recursively, subpackages. Technically, a package is a Python module with an
__path__
attribute.
So every (sub-)package is also a module, but the opposite is not true.
Considering the package layout you gave as an example:
A
├── B.py
├── C
│ ├── D.py
│ └── __init__.py
└── __init__.py
Here, A, B, C, D
are all modules (you can import them via their name: import A
or import A.B
or import A.C
or import A.C.D
). However only A, C
are considered packages.
Upvotes: 1