What’s the difference between a Python module and a Python package?

Technology CommunityCategory: PythonWhat’s the difference between a Python module and a Python package?
VietMX Staff asked 3 years ago

Any Python file is a module, its name being the file’s base name without the .py extension.

import my_module

package is a collection of Python modules: while a module is a single Python file, a package is a directory of Python modules containing an additional init.py file, to distinguish a package from a directory that just happens to contain a bunch of Python scripts. Packages can be nested to any depth, provided that the corresponding directories contain their own init.py file.

Packages are modules too. They are just packaged up differently; they are formed by the combination of a directory plus init.py file. They are modules that can contain other modules.

from my_package.timing.danger.internets import function_of_love