importutils.py 文件源码

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

项目:figura 作者: shx2 项目源码 文件源码
def _raw_import(path):
    # First, invalidate caches!
    # From the docs:
    # "If you are dynamically importing a module that was created since the interpreter began execution
    # (e.g., created a Python source file), you may need to call invalidate_caches() in order for the
    # new module to be noticed by the import system."
    # Since we're dealing with config files, we need to support re-reading config files
    # which are modified after the interpreter started.
    # See:
    # https://docs.python.org/3/library/importlib.html#importlib.import_module
    # https://docs.python.org/3/library/importlib.html#importlib.invalidate_caches
    try:
        invalidate_caches = importlib.invalidate_caches
    except AttributeError:
        # python2
        pass
    else:
        # python3
        invalidate_caches()
    # Now can safely import the module
    return importlib.import_module(path)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号