steffentools package¶
Module contents¶
A collection of useful tools.
Submodules¶
steffentools.dict_to_ntuple module¶
The dict_to_ntuple module, containing the dict_to_ntuple function.
-
steffentools.dict_to_ntuple.
dict_to_ntuple
(input_value)¶ Recursively convert a dict to a nested namedtuple.
Parameters: input_value (any) – The input value to the function can be any type of data. If it is a dict, dict_to_ntuple will attempt to create a namedtuple from it, deriving attribute names from the dict’s keys. If the input_value is a collection, such as a list or tuple, dict_to_ntuple will iterate through it, attempting to convert each of its values to a namedtuple. If the input_value is any other data type, dict_to_ntuple will return it as-is. Returns: If possible, this function will return a nested namedtuple representing the original input_value with keys converted into attribute names. For inputs that cannot be converted to a namedtuple, the function will either return the original value (if not iterable) or will iterate over the input_value and attempt to convert each member in the same way before returning the converted input_value. Return type: namedtuple (or original datatype)