treevalue.utils.imports¶
import_object¶
-
treevalue.utils.imports.import_object(obj_name: str, module_name: Optional[str] = None)[source]¶ - Overview:
Dynamically import an object from module.
- Arguments:
obj_name (
str): Name of the object.module_name (
Optional[str]): Name of the module, default isNonewhich means thebuiltinsmodule.
- Returns:
obj: Imported object.
- Example::
>>> import_object('zip') # <class 'zip'> >>> import_object('ndarray', 'numpy') # <class 'numpy.ndarray'>
quick_import_object¶
-
treevalue.utils.imports.quick_import_object(full_name: str, predicate: Optional[Callable] = None) → Tuple[Any, str, str][source]¶ - Overview:
Quickly dynamically import an object with a single name.
- Arguments:
full_name (
str): Full name of the object, attribute is supported as well.predicate (
Callable): Predicate function, default isNonemeans no limitation.
- Returns:
obj (
Tuple[Any, str, str]): Imported object.
- Example::
>>> quick_import_object('zip') # <class 'zip'>, '', 'zip' >>> quick_import_object('numpy.ndarray') # <class 'numpy.ndarray'>, 'numpy', 'ndarray' >>> quick_import_object('numpy.ndarray.__name__') # 'ndarray', 'numpy', 'ndarray.__name__'
iter_import_objects¶
-
treevalue.utils.imports.iter_import_objects(full_pattern: str, predicate: Optional[Callable] = None) → Iterator[Tuple[Any, str, str]][source]¶ - Overview:
Quickly dynamically import all objects with full name pattern.
- Arguments:
full_pattern (
str): Full pattern of the object, attribute is supported as well.predicate (
Callable): Predicate function, default isNonemeans no limitation.
- Returns:
iter (
Iterator[Tuple[Any, str, str]]): Iterator for all the imported objects.