To load the file in Python 3.5 you can run the following code:-
import importlib.util
spec = importlib.util.spec_from_file_location("module.name", "/path/to/file.py")
foo = importlib.util.module_from_spec(spec) spec.loader.exec_module(foo)
foo.MyClass()
For Python 3.3 and 3.4 use the following piece of code:-
from importlib.machinery import SourceFileLoader
foo = SourceFileLoader("module.name", "/path/to/file.py").load_module()
foo.MyClass()
If you are Python 2 user you can run the following code:-:
import imp
foo = imp.load_source('module.name', '/path/to/file.py') foo.MyClass()