【发布时间】:2013-05-26 20:34:03
【问题描述】:
我同意有类似的问题,但没有一个符合我的目的。
我既不能更改文件名也不能添加符号链接。文件名很重要。
我已经尝试了以下
>>> imp.load_source('test','.')
<module 'test' from '.'>
和
>>> importlib.import_module('test','.')
<module 'test' from '.'>
test 模块在哪里
print 'hello world'
test.py,则导入语句的工作方式与导入时一样,即在导入时打印hello world。有什么方法可以“运行”使用 imp 或 imortlib 导入的模块?
我想补充一点,我说的是autotest project 中的一个control 文件,如果重要的话。
【问题讨论】:
-
我不这么认为,我已经试过了。我说必须执行导入的模块。imp没有发生这种情况
-
模块在导入时执行。