转自:

http://www.linuxany.com/archives/1563.html

 

 

Python 动态加载模块的3种方法

1,使用系统函数__import_()

  1. stringmodule = __import__('string')

2,使用imp 模块

  1. import imp
  2. stringmodule = imp.load_module('string',*imp.find_module('string'))

3,使用exec

  1. import_string = "import string as stringmodule"
  2. exec import_string
 

 

完!

相关文章:

  • 2022-12-23
  • 2021-08-16
  • 2022-12-23
  • 2021-10-27
  • 2022-03-10
  • 2022-12-23
  • 2022-02-13
  • 2021-09-25
猜你喜欢
  • 2021-07-19
  • 2022-12-23
  • 2021-10-06
  • 2022-12-23
  • 2021-05-17
  • 2022-02-06
相关资源
相似解决方案