Show More
@@ -1,13 +1,14 b'' | |||
|
1 | import imp | |
|
1 | import importlib | |
|
2 | 2 | |
|
3 | 3 | |
|
4 | 4 | def create_module(name, path): |
|
5 | 5 | """ |
|
6 | 6 | Returns module created *on the fly*. Returned module would have name same |
|
7 | 7 | as given ``name`` and would contain code read from file at the given |
|
8 | 8 | ``path`` (it may also be a zip or package containing *__main__* module). |
|
9 | 9 | """ |
|
10 | module = imp.new_module(name) | |
|
11 | module.__file__ = path | |
|
12 | exec(compile(open(path, "rb").read(), path, 'exec'), module.__dict__) | |
|
10 | ||
|
11 | spec = importlib.util.spec_from_file_location('module_name', path) | |
|
12 | module = importlib.util.module_from_spec(spec) | |
|
13 | spec.loader.exec_module(module) | |
|
13 | 14 | return module |
General Comments 0
You need to be logged in to leave comments.
Login now