字符串形式导入模块

import importlib
importlib.import_module('app01')
<module 'app01' from 'D:\my-ws-python\b_othersource\pub_school_crm\dj_crm\app01\__init__.py'>
importlib.import_module('app01.models')
<module 'app01.models' from 'D:\my-ws-python\b_othersource\pub_school_crm\dj_crm\app01\models.py'>
m=importlib.import_module('app01.models')
m.UserProfile
<class 'app01.models.UserProfile'>
原文地址:https://www.cnblogs.com/infaaf/p/9418264.html