https://blog.csdn.net/foryouslgme/article/details/51734833
Deprecated since version 3.4: The imp package is pending deprecation in favor of importlib.
与之相关的:
1、系统函数_import()
2、exec
#Python的import不能接受变量,所以应该用 __import__函数来动态导入。
#如下的代码无法正常导入模块
modules = ['OpenSSL', 'Crypto', 'MySQLdb', 'sqlite3', 'zope.interface', 'pyasn1', 'twisted', 'django']
for each in modules:
try:
import each
except Exception, e:
print e
#这样导入会抛出 No module named each 的异常 将 import each 改为 __import__(each)就可以正常导入了。
importlib.find_loader(name, path=None) Deprecated since version 3.4: Use importlib.util.find_spec() instead.