python importlib

api 文档

importlib.import_module(namepackage=None)

Import a module. The name argument specifies what module to import in absolute or relative terms (e.g. either pkg.mod or ..mod). If the name is specified in relative terms, then the package argument must be specified to the package which is to act as the anchor for resolving the package name (e.g. import_module('..mod', 'pkg.subpkg') will import pkg.mod). The specified module will be inserted into sys.modules and returned.

>>> import importlib
>>> s = importlib.import_module('os.path')
>>> s
<module 'ntpath' from 'D:softwarepython2.7lib tpath.pyc'>
>>> s

原文地址:https://www.cnblogs.com/chens-smile/p/3484392.html