I have __init__.py file in current directory.
I need a complete list of circumstances, under which this file will run.
First case is
import __init__
written in the script.py in the same directory and this file runs.
What are other cases?
I have __init__.py file in current directory.
I need a complete list of circumstances, under which this file will run.
First case is
import __init__
written in the script.py in the same directory and this file runs.
What are other cases?
A __init__.py file is run when the package that the corresponds to it is imported. So a file some_package\__init__.py is executed when you import some_package. When you import a submodule from a package the package is first loaded. So import aa.bb.cc, will load aa (and thus execute aa/__init__.py) before loading aa.bb and aa.bb.cc.
The folder some_package must be discoverable, which means that it must exists in one of the sys.path folders. This includes the current directory.
If you simply run a script (python some_script.py) and there happens to be a __init__.py file in the same folder then this means nothing, since the current folder is not a package itself. (unless of course if you execute a script that happens to reside inside a package).