modules.py 文件源码

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

项目:zoocore 作者: dsparrow27 项目源码 文件源码
def importModule(modulePath, name=""):
    if isDottedPath(modulePath) or not os.path.exists(modulePath):
        try:
            return __import__(modulePath, fromlist="dummy")
        except ImportError:
            logger.debug("failed to load module->%s" % modulePath, exc_info=True)

    try:
        if os.path.exists(modulePath):
            if not name:
                name = os.path.splitext(os.path.basename(modulePath))[0]
            if name in sys.modules:
                return sys.modules[name]
            if os.path.isdir(modulePath):
                modulePath = os.path.join(modulePath, "__init__.py")
                if not os.path.exists(modulePath):
                    raise ValueError("Cannot find modulepath: {}".format(modulePath))
            return imp.load_source(name, os.path.realpath(modulePath))
    except ImportError:
        logger.error("Failed to load module {}".format(modulePath))
        raise
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号