get_nested#
- ptyrad.utils.common.get_nested(d, key, delimiter='.', safe=False, default=None)[source]#
Get a value from a nested dictionary either safely (return default if not found) or stricly to fail early.
Parameters: - d (dict): The dictionary to traverse. - key (str, or list or tuple of string): A sequence of keys to access nested values. - delimiter (str): The string used to seperate different parts of the displayed key path - safe (boolean): The flag to switch between safe/strict mode of getting values from a nested dict. - default: The value to return if any key is missing or intermediate value is None.
Returns: - The nested value if found, otherwise default in safe mode or error in strict mode.