Can someone help and clarify, when using import
command(s), at which moment the __init__.py files in various package directory(s) is/are executed?
- For each included module?
- Only once at 1st
import
command? - For each
import
command?
Can someone help and clarify, when using import
command(s), at which moment the __init__.py files in various package directory(s) is/are executed?
import
command?import
command?
It's evaluated on first module import. On next imports, interpreter detects that module was already loaded and simply returns reference to it. There is no need to re-execute code.
Quoting The import system:
On caching modules:
On executing
__init__
when importing: