Skip to content

Utils

get_obj_from_string(import_string)

Retrieves an object based on an import string.

The import string should specify the full path to the desired object, starting from the root module. This function dynamically imports the module and retrieves the specified object (which can be a class, function, or any other Python object).

PARAMETER DESCRIPTION
import_string

The import string, which is a dot-separated string representing the module path and the object name. For example: "os.path.join" or "my_module.MyClass".

TYPE: str

RETURNS DESCRIPTION
object

The object identified by the import string.

RAISES DESCRIPTION
ImportError

If the module specified in the import string cannot be found.

AttributeError

If the object specified in the import string does not exist within the imported module.

Examples:

import os

join_func = get_obj_from_string("os.path.join")
assert join_func is os.path.join

simple_generator(iterable)

Iterates through an iterable and yields each item.

PARAMETER DESCRIPTION
iterable

The iterable to yield elements from.

TYPE: Iterable[Any]

YIELDS DESCRIPTION
Any

An element from the input iterable.

Examples:

list(simple_generator([1, 2, 3]))
# Expected output: [1, 2, 3]
list(simple_generator("abc"))
# Expected output: ['a', 'b', 'c']