I am trying to figure out an efficient way to initialize modules so my functions in different files can use them.
Here's an example folder structure
parent/
main.py
child/
__init__.py
utilities.py
My scripts have multiple functions that depend on many other modules. So my plan was this:
I import modules I need from the main python file.
main.py
import time
from child.utilities import *
utilities_function1()
utilities_function2()
Use the from .. import main
in child functions to pull the modules from the parent file.
utilities.py
def utilities_function1():
from .. import main
print(time.localtime())
def utilities_function2():
from .. import main
print(time.localtime()+1)
However, the problem I have is that I am repeating the from .. import
main for every single function in the child python file. This doesn't seem like a best practice to me so is there a more efficient way to do this?