How can I `import *` from a module loaded with imp?

不问归期 提交于 2019-12-23 18:55:46

问题


I currently work with keras and custom activation functions. I store those models as pickle and I would like to be able to load them again. Then I run into this issue.

The problem is that the Python script which contains the custom activation function is given by path. I load this script via

import imp
model_module = imp.load_source('model', experiment_meta['model']['script_path'])

How can I "star import" (import *) in this case to make the loading of the trained model work?

What I've tried

from model_module import *

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named model_module

回答1:


I just found the answer:

from model import *


来源:https://stackoverflow.com/questions/43931591/how-can-i-import-from-a-module-loaded-with-imp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!