Is __init__.py file is a module ? I am learning python and come across packages and modules and i have one doubt that weather __init__.py file can be consider as module Since every python file is module so can we consider __init__.py as module ?
1 Answer
According to the official glossary a module is
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.
Which (imho) borders on gibberish for saying "module objects or files with Python code."
Since even an empty __init__.py file contains valid Python code, and you can import it via import __init__, it would technically be considered a module.
I don't know how this knowledge could be useful.
__init__.pyis a module has exactly 0 practical benefits. It really doesn't matter one bit.__init__.pyfile could not be considered a module. It's a package, and as such it can be imported, butimport packageis basically syntactic sugar forimport package.__init__ as package, right?