utils.py 文件源码

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

项目:restfulpy 作者: Carrene 项目源码 文件源码
def import_python_module_by_filename(name, module_filename):
    """
    Import's a file as a python module, with specified name.

    Don't ask about the `name` argument, it's required.

    :param name: The name of the module to override upon imported filename.
    :param module_filename: The filename to import as a python module.
    :return: The newly imported python module.
    """

    sys.path.append(abspath(dirname(module_filename)))
    spec = importlib.util.spec_from_file_location(
        name,
        location=module_filename)
    imported_module = importlib.util.module_from_spec(spec)
    spec.loader.exec_module(imported_module)
    return imported_module
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号