1 Star 0 Fork 3

kentzhang/python-agent

forked from kentzhang/python-sdk 
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
module_loading.py 781 Bytes
一键复制 编辑 原始数据 按行查看 历史
kentzhang 提交于 2019-07-03 15:09 +08:00 . first blood of python-sdk
from importlib import import_module
from typing import Any
def import_string(dotted_path: str) -> Any:
"""
Source: django.utils.module_loading
Import a dotted module path and return the attribute/class designated by the
last name in the path. Raise ImportError if the import failed.
"""
try:
module_path, class_name = dotted_path.rsplit(".", 1)
except ValueError:
msg = "%s doesn't look like a module path" % dotted_path
raise ImportError(msg)
module = import_module(module_path)
try:
return getattr(module, class_name)
except AttributeError:
msg = 'Module "%s" does not define a "%s" attribute/class' % (
module_path,
class_name,
)
raise ImportError(msg)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/coderkent/python-agent.git
git@gitee.com:coderkent/python-agent.git
coderkent
python-agent
python-agent
master

搜索帮助