如何使用__import__导入* [英] How to import * with __import__
本文介绍了如何使用__import__导入*的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用 __ import __
执行以下操作的最佳方法是什么,以便我可以动态指定模块?
What's the best approach to execute the following using __import__
so that I may dynamically specify the module?
from module import *
推荐答案
它与普通的从导入调用相同,你只需传递一个包含'*'
的列表,用于 fromlist
:
It's the same as a normal from-import call, you just pass it a list containing '*'
for the fromlist
:
moduleName = "foo"
__import__(moduleName, globals(), locals(), ['*'])
这篇关于如何使用__import__导入*的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文