importer.py 文件源码

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

项目:aquests 作者: hansroh 项目源码 文件源码
def importer (directory, libpath, module = None):
    fn = not libpath.endswith (".py") and libpath + ".py" or libpath
    modpath = os.path.join (directory, fn)
    hname = fn.split (".")[0]
    p = directory.replace ("\\", "/")
    if p.find (":") !=- 1:
        p = "/" + p.replace (":", "")
    while 1:
        if "skitai.mounted." + hname in sys.modules:                
            p, l = os.path.split (p)
            if not l:
                raise SystemError ('module %s already imported, use reload')
            hname = l + "." + hname
        else:
            hname = "skitai.mounted." + hname
            break

    loader = importlib.machinery.SourceFileLoader(hname, modpath)
    mod = loader.load_module ()

    return mod, mod.__file__
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号