""" Two methods to insert a dictionary tree node : - create a sausage element; add the element in original dictionary - insert directly in original dictionary """ insert_node(self, dot_name, value): """ Insert a MAPPED node :param dot_name: string name such as 'x.y.z' :param value: value of the dotted item """ try: dot_name_str = str(dot_name) name_list = dot_name_str.split('.') key = name_list[-1] """ # Create a sausage element first sausage_element = {key: str(value)} for i in reversed(name_list[:-1]): sausage_element = {i:sausage_element} # insert the element into dict dictionary = self.original_dict for i in name_list: if dictionary.has_key(i): dictionary = dictionary[i] sausage_element = sausage_element[i] else: dictionary[i] = sausage_element[i] break """ # insert the element into dict dictionary = self.original_dictionary for i in name_list[:-1]: if not dictionary.has_key(i): dictionary[i] = {} dictionary = dictionary[i] dictionary[name_list[-1]] = str(value) except Exception as e print e