There are answers for when both scripts are in the same directory.
However, I can't get any of the answers mentioned here working for a relative path. They are for when the full path is known.
I have the following folder hierarchy
i need to call and run sub.py in commander.py
the following is in commander.py
import importlib.util
spec = importlib.util.spec_from_file_location('sub.py', '..//main/sub/sub.py')
foo = importlib.util.module_from_spec(spec)
spec.loader.exec_module(foo)
foo.main()
it certainly recognized the directory as I can see the pycache 'folder getting created in sub folder.
However the sub script doesn't run. I have launched the sub script manually and i know it is functional.
the sub script has the following structure
import stuff
def main():
do stuff
return
while true:
main()
break
I am new to python. I have also tried:
import sys
sys.path.insert(0, '..\\main\sub')
import sub.py
sub.main()
i'm using py 3.7 there are no errors