django—importlib模块
1、作用
通过字符串导入同名的模块
字符串为模块的路径:绝对路径、相对路径
2、示例
目录结构
aaa
bbb
m1.py
m2.py
m1.py和m2.p文件
# m1.py
print('from m1')
# m2.py
import importlib
s = 'bbb.m1'
md = importlib.import_module(s)
print(md)
'''
m2中执行结果为:
from m1
<module 'bbb.m1' from 'C:\\Users\\Administrator\\PycharmProjects\\aaa\\bbb\\m1.py'>
'''