1
我仍然与我的URL转换器的URL,但我有一个问题。 我想导入x。 我说:如何导入列表中的项目?
for x in range(1, 7):
import imports[x]
time.sleep(0.1)
我希望它导入列表imports
项目x
。我该怎么做?
我仍然与我的URL转换器的URL,但我有一个问题。 我想导入x。 我说:如何导入列表中的项目?
for x in range(1, 7):
import imports[x]
time.sleep(0.1)
我希望它导入列表imports
项目x
。我该怎么做?
这就是你想要的吗?
import importlib
for i in ['a', 'b', 'c']:
importlib.import_module('foo.' + i)
如果你想要的东西更灵活,你可以使用exec
x = 'foo'
y = 'bar'
exec('from ' + x + ' import ' + y, locals(), globals())
没有,试图importlib.import_module(进口[X])。并给出错误。 – AlexINF
@ Alex82有什么错误?你正在使用Python 2或Python 3? – Macabeus
哎呀,忘了点安装! – AlexINF