mmengine.utils.import_modules_from_strings¶
- mmengine.utils.import_modules_from_strings(imports, allow_failed_imports=False)[源代码]¶
Import modules from the given list of strings.
- 参数
imports (list | str | None) – The given module names to be imported.
allow_failed_imports (bool) – If True, the failed imports will return None. Otherwise, an ImportError is raise. Default: False.
- 返回
The imported modules.
- 返回类型
list[module] | module | None
实际案例
>>> osp, sys = import_modules_from_strings( ... ['os.path', 'sys']) >>> import os.path as osp_ >>> import sys as sys_ >>> assert osp == osp_ >>> assert sys == sys_