python_humble_utils package¶
Subpackages¶
Submodules¶
python_humble_utils.classes module¶
-
python_humble_utils.classes.
get_all_subclasses
(cls: Type[CT_co], including_self: bool = False) → Collection[Type[CT_co]][source]¶ Get all subclasses.
Parameters: - cls – class to lookup subclasses of.
- including_self – whether or not the the :param cls: itself is to be accounted for.
Returns: param cls: subclasses.
python_humble_utils.filesystem module¶
-
python_humble_utils.filesystem.
create_or_update_file
(file_path: str, file_content: str = '', file_content_encoding: str = 'utf-8') → None[source]¶ Create or update file.
Parameters: - file_path – path to the file.
- file_content – file content.
- file_content_encoding – file content encoding e.g. latin-1.
-
python_humble_utils.filesystem.
generate_random_dir_path
(root_dir_path: Optional[pathlib.Path] = None, subdir_count: int = 0, random_string_generator: Optional[Callable[[], str]] = None) → pathlib.Path[source]¶ Generate a random directory path.
Parameters: - root_dir_path – root dir path; by default, the current dir path is used
- subdir_count – a number of subdirectories to generate in the directory root.
- random_string_generator – random number generator; by default, the UUID4 hex is used
Returns: directory root path.
-
python_humble_utils.filesystem.
read_file
(file_path: str, as_single_line: bool = False) → str[source]¶ Read file content.
Parameters: - file_path – path to the file.
- as_single_line – whether or not the file is to be read as a single line.
Returns: file content.
-
python_humble_utils.filesystem.
yield_file_paths
(dir_path: pathlib.Path, allowed_file_extensions: Collection[str], recursively: bool = False) → Iterable[pathlib.Path][source]¶ Yield file paths.
Parameters: - dir_path – path to the containing directory.
- allowed_file_extensions – file extensions to match against e.g. [‘.abc’, ‘.def’].
- recursively – whether or not the directory is to be recursively traversed.
Returns: file paths.
python_humble_utils.objects module¶
-
python_humble_utils.objects.
flatten
(obj: Any, flatten_dicts_by_values: bool = True, coerce: Optional[Callable[[T], M]] = None) → Iterable[M][source]¶ Flatten an arbitrarily complex object.
Parameters: - obj – an obj to flatten.
- flatten_dicts_by_values – if True, mapping will be flattened by values, otherwise by keys.
- coerce – a callable used to coerce items of the resulting iterable to
Returns: a recursively-constructed iterable of the object’s constituents.
python_humble_utils.strings module¶
-
python_humble_utils.strings.
camel_or_pascal_case_to_snake_case
(s: str) → str[source]¶ Convert camelCased or PascalCased string to snake_case.
Based on https://stackoverflow.com/a/1176023/1557013.
Parameters: s – string in camelCase or PascalCase. Returns: string in snake_case.
-
python_humble_utils.strings.
camel_or_pascal_case_to_space_delimited
(s: str) → str[source]¶ Convert camelCased or PascalCased string to space-delimited.
Based on https://stackoverflow.com/a/9283563/1557013.
Parameters: s – string in camelCase or PascalCase. Returns: space-delimited string.