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
评论列表
文章目录