lundi 10 juin 2019

[Python] Difference between package and module

A module is a file :-) Modules are used to keep logically related code functions/classes together.


A package is a folder containing a set of modules.

A package may contain sub-packages.

A package must have a __init__.py at the root of the directory. When a package is imported, this __init__.py file is implicitly executed. https://docs.python.org/3/reference/import.html#regular-packages

Packaging help you to keep logically related set of modules together just as modules are used to keep logically related code functions/classes together.

With Python 3.3 and later, a package is called a regular package, and a new type of package appears : namspace package. https://docs.python.org/3/reference/import.html#namespace-packages

Aucun commentaire:

Categories