Currently, I have the directory to a file
"../Model.py"
This model has a class called Test.
Using the string of the directory, I want to import and use the class Test.
How do I do so?
(The String will change dynamically)
Currently, I have the directory to a file
"../Model.py"
This model has a class called Test.
Using the string of the directory, I want to import and use the class Test.
How do I do so?
(The String will change dynamically)
From: https://docs.python.org/3/tutorial/modules.html#the-module-search-path
I tested this and I believe it should work for you as well. The code should look as follows:
import sys
directory = '../Model.py'
directory = directory[:-8]
sys.path.append(directory)
from Model import Test