About Triggering __init__.py

When you import from a deeply nested module in Python, __init__.py will be executed for each module in the path starting from the root (if it hasn't been executed before).

For example:

1
2
3
4
>>> from m1.m2.m3 import *
m1/__init__.py triggered
m2/__init__.py triggered
m3.py triggered

Tips and Tricks Programming Python 3