问题描述
我想做类似以下的事情,这些都行不通:
modulename =''模块''
导入模块名
错误是没有名为''modulename''的模块。是否有一个
方式来扩展变量?
问候,
史蒂文
modulename =''module''
module = __import __(modulename )
Hye-Shik
缩进错误?
modulename =''module''
cmd =''import''+ modulename
exec(cmd)
检查主题:
如何导入子目录中的所有内容?
在此新闻组中。
请注意,它告诉您使用__import__,而不是exec。 =)
STeVe
Hi,
I want to do something like the following, which doesn''t work:
modulename = ''module''
import modulename
The error is that there is no module named ''modulename''. Is there a
way to get that variable expanded?
Regards,
Steven
modulename = ''module''
module = __import__(modulename)
Hye-Shik
indentation error?
modulename = ''module''
cmd = ''import ''+modulename
exec(cmd)
Check also the thread:
How do I import everything in a subdir?
in THIS newsgroup.
And note that it tells you to use __import__, not exec. =)
STeVe
这篇关于可以导入名称包含在变量中的模块吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!