Consider the following directory structure:
project/
scripts/
a1.py
a2.py
start.py
start.py
depends on a1.py
and a1.py
in turn uses a function called some_func
which is present in a2.py
. Moreover, a1.py
is also a standalone script and can be called independently. Now this gives rise two cases:
Case 1: (Standalone script) I would import some_func as follows
from a2 import some_func
Case 2: (Called from start.py
)
from scripts.a2 import some_func
My Question: What is the pythonic way of combining the two use cases?
Possible Solution?: Is this recommended or not?
if __name__ == "__main__":
from a2 import some_func
elif __name__ == "start":
from scripts.a2 import some_func
Note: I am using python 3.x