importlib 模块

Python提供了importlib包作为标准库的一部分。目的就是提供Python中import语句的实现(以及__import__函数)。另外,importlib允许程序员创建他们自定义的对象,可用于引入过程(也称为importer)。

#举例自定义一个模块aa,内部函数为:
class c(object):
def __str__(self):
return 'C language'

# 字符串导入函数2种方法,建议方法
import importlib
aa = importlib.import_module('lib.aa')
c = aa.c()
print(c)

# 第二种方法,已淘汰
lib = __import__('lib.aa')
print(lib)
c = lib.aa.c()
print(c)

相关文章:

  • 2021-10-06
  • 2022-02-24
  • 2021-06-19
  • 2021-12-20
  • 2021-06-13
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-06-25
  • 2021-12-23
  • 2021-12-08
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案