As root
has an __init__
file, it's a module.
When you run a from module import..
, it executes any code in that modules __init__
.
And since your __init__
contains a print
, that gets executed.
Since you're running __init__
directly (Which you shouldn't do btw), it's doing the following:
-> from root import RequestHandler
-> root.__init__:
-> import RequestHandler
-> print("Test")
-> print("Test")
The __init__
is useful for checking presence of any modules, or fallbacks, or checking a python version.
For example, this __init__.py
will not let any versions of Python less than 400 import the module:
import sys
if not hasattr(sys, "version_info") or sys.version_info < (400, 0):
raise RuntimeError("root requires Python 400.0 or later.")
del sys
from root import RequestHandler
print("Test")
Let's hope it updates til the end of time then.