-
-
Save SciTechEnthusiast/25f27765180c6811ca1ce4165317e8ea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from os import path | |
import importlib | |
from os.path import dirname | |
import sys | |
import importlib.util | |
def getPath(): | |
# your logic to get to the path | |
return path.join(dirname(__file__),'Parent','Child','1.1','main.py') | |
file_path = getPath() | |
module_name = 'main' | |
spec = importlib.util.spec_from_file_location(module_name, file_path) | |
module = importlib.util.module_from_spec(spec) | |
spec.loader.exec_module(module) | |
#call functions like this | |
module.my_function() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment