Skip to content
Snippets Groups Projects
Commit d70e85a2 authored by Pepping's avatar Pepping
Browse files

Added two function: remove_all_but_the_dict_from_list and get_key_value

parent 5c8a53fa
No related branches found
No related tags found
No related merge requests found
......@@ -115,6 +115,19 @@ class CommonDictFile:
self.filePathNames.pop(k)
self.dicts.remove(the_dict)
self.nof_dicts -= 1
def remove_all_but_the_dict_from_list(self, the_dict):
"""Remove all dicts from the internal list of dicts from the available dictionary files, except the_dict."""
k = self.dicts.index(the_dict)
filePath = self.filePaths[k]
filePathName = self.filePathNames[k]
self.filePaths = []
self.filePaths.append(filePath)
self.filePathNames = []
self.filePathNames.append(filePathName)
self.dicts = []
self.dicts.append(the_dict)
self.nof_dicts = 1
def find_all_dict_file_paths(self, rootDir=None):
"""Recursively search the rootDir tree to find the paths to all fileName files."""
......@@ -279,6 +292,15 @@ class CommonDictFile:
key_values.append(None)
return cm.unlistify(key_values)
def get_key_value(self, key, dict=None):
"""Get the value of a key from a single dict or None in case the key does not exist."""
if dict==None: dict=self.dicts[0]
if key in dict:
key_value = dict[key]
else:
key_value = None
return key_value
def get_dicts(self, key, values=None, dicts=None):
"""Get all dictionaries in dicts that contain the key with a value specified in values. If values==None then
get all dictionaries in dicts that contain the key.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment