Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python docs: confusing terminology of modules and submodules

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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?

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading