I'm starting to work deeper with Python and have noticed many projects with __int__.py
files in folders, and are often blank.
What is the purpose of these files?
I'm starting to work deeper with Python and have noticed many projects with __int__.py
files in folders, and are often blank.
What is the purpose of these files?
It is part of a package. See Python documentation .
__init__.py
files are required to make Python handle the directories that contain the packages, this is done to avoid directories with common names, such asstring
, that involuntarily hidden in the valid modules, those that will be searched in the way. In the simplest case, the__init__.py
file can only be one file, but it also runs the boot code for the package or set the variable__all__
, described later.
The __init__.py files are used to declare to the python interpreter that the directory they are in contains python files in the program. Example:
diretoria/
__init__.py
ficheiro_a.py
ficheiro_b.py
ficheiro_c.py