I was reading a document and I encountered the part below:
A module is nothing more, nothingless than a directory with __init__.py file inside. It should contain other Python files with the logic related to the module's purpose.
Is this definition correct?
(As I know, a Python module is a file, whose extension is py, which contains Python code. And as I remember a directory which contains dunder init(__init__.py) file is called as Python package.)
1 Answer 1
The definition is incorrect.
While a "package" is also a "module", a single ".py" file comprises, in itself,
a module, with no need to be a directory, or have an __init__ file inside it.
A package, on the other hand, yes, is usually (and defined as) a directory with an __init__.py and optionally other files.
(However packages can be presented in other formats such as .egg or zip files, or even custom formats with corresponding customized importing mechanisms, which are plugable)
Comments
Explore related questions
See similar questions with these tags.
__init__.py.