X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_lcm%2Flcm_utils.py;h=a83e788636c588b41c2d5ad31394c61e76cd4240;hb=626e0150294da773c136d444d000e1a8b4521dea;hp=b4e6887d4e14518d3ad476d326d1b1877fa1c526;hpb=5899e08821d446ce8e036aa59a3451487b1bd0b3;p=osm%2FLCM.git diff --git a/osm_lcm/lcm_utils.py b/osm_lcm/lcm_utils.py index b4e6887..a83e788 100644 --- a/osm_lcm/lcm_utils.py +++ b/osm_lcm/lcm_utils.py @@ -49,6 +49,21 @@ def versiontuple(v): return tuple(filled) +def deep_get(target_dict, key_list): + """ + Get a value from target_dict entering in the nested keys. If keys does not exist, it returns None + Example target_dict={a: {b: 5}}; key_list=[a,b] returns 5; both key_list=[a,b,c] and key_list=[f,h] return None + :param target_dict: dictionary to be read + :param key_list: list of keys to read from target_dict + :return: The wanted value if exist, None otherwise + """ + for key in key_list: + if not isinstance(target_dict, dict) or key not in target_dict: + return None + target_dict = target_dict[key] + return target_dict + + # LcmBase must be listed before TaskRegistry, as it is a dependency. class LcmBase: