Skip to content

Instantly share code, notes, and snippets.

@SciTechEnthusiast
Created November 20, 2021 06:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SciTechEnthusiast/25f27765180c6811ca1ce4165317e8ea to your computer and use it in GitHub Desktop.
Save SciTechEnthusiast/25f27765180c6811ca1ce4165317e8ea to your computer and use it in GitHub Desktop.
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