Context.py 文件源码

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

项目:SoCFoundationFlow 作者: mattaw 项目源码 文件源码
def load_module(path, encoding=None):
    """
    Load a source file as a python module.

    :param path: file path
    :type path: string
    :return: Loaded Python module
    :rtype: module
    """
    try:
        return cache_modules[path]
    except KeyError:
        pass

    module = imp.new_module(WSCRIPT_FILE)
    try:
        code = Utils.readf(path, m='rU', encoding=encoding)
    except EnvironmentError:
        raise Errors.WafError('Could not read the file %r' % path)

    module_dir = os.path.dirname(path)
    sys.path.insert(0, module_dir)

    try    : exec(compile(code, path, 'exec'), module.__dict__)
    finally: sys.path.remove(module_dir)

    cache_modules[path] = module

    return module
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号