CopyPastor

Detecting plagiarism made easy.

Score: 1.8107851147651672; Reported for: String similarity, Exact paragraph match Open both answers

Possible Plagiarism

Plagiarized on 2022-01-18
by Coco Cat

Original Post

Original - Posted on 2008-09-15
by Sebastian Rittau



            
Present in both answers; Present only in the new answer; Present only in the old answer;

The following code snippets will allow you to load modules by explicitly defining the path to the required module(s):
For Python 3.5+ use:
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:
from importlib.machinery import SourceFileLoader foo = SourceFileLoader("module.name", "/path/to/file.py").load_module() foo.MyClass()
(Although this has been deprecated in Python 3.4.)
For Python 2 use:
import imp foo = imp.load_source('module.name', '/path/to/file.py') foo.MyClass()
For Python 3.5+ use:
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:
from importlib.machinery import SourceFileLoader
foo = SourceFileLoader("module.name", "/path/to/file.py").load_module() foo.MyClass()
(Although this has been deprecated in Python 3.4.)
For Python 2 use:
import imp foo = imp.load_source('module.name', '/path/to/file.py') foo.MyClass()
There are equivalent convenience functions for compiled Python files and DLLs.
See also http://bugs.python.org/issue21436.

        
Present in both answers; Present only in the new answer; Present only in the old answer;