utils.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:django-rest-framework-client 作者: qvantel 项目源码 文件源码
def lookup_by_objref(objref):
    """
    Imports an object by an ObjRef object.

    If ObjRef object also contains module attribute, it will also attempt to relative import from it
    when absolute import was not successful.
    """
    obj = pydoc.locate(objref.name)
    if obj is None:
        if objref.module is None:
            raise ImportError('Unable to import "%s"' % (objref.name))
        path = '.'.join([objref.module, objref.name])
        obj = pydoc.locate(path)
        if obj is None:
            raise ImportError('Unable to import "%s" nor "%s"' % (objref.name, path))
    return obj
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号