Python标准库:内置函数__import__(name, globals=None, locals=None, fromlist=(), level=0)

来源:互联网 发布:淘宝骗运费险违法吗 编辑:程序博客网 时间:2024/05/04 05:24

本函数实现导入模块的功能。这个函数主要为了语句import的功能而实现的,大多数情况之下,是不需要直接使用这个函数。比如想动态地加载模块,才需要使用这个函数。

例子:

import glob,os    modules = []  for module_file in glob.glob("*-plugin.py"):      try:         module_name,ext = os.path.splitext(os.path.basename(module_file))         module = __import__(module_name)         modules.append(module)      except ImportError:         pass #ignore broken modules      #say hello to all modules      for module in modules:         module.hello()  

到这里,所有内置函数全部学习完成。


蔡军生 QQ:9073204  深圳

0 0
原创粉丝点击