X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=fba%2Fhelpers%2Fdicts.py;h=cd9ccbde4ae4c5c8f436719423cbf2a032351f0f;hb=21c7c13dcdf897008a7f340e606c947092ba51bd;hp=68209139d8a1e5fef8befad4aa582a1ee19e77f1;hpb=ca57258e9e940dfc2f2bcae094f9cefb4c6de469;p=fba.git diff --git a/fba/helpers/dicts.py b/fba/helpers/dicts.py index 6820913..cd9ccbd 100644 --- a/fba/helpers/dicts.py +++ b/fba/helpers/dicts.py @@ -13,26 +13,34 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +import logging + +logging.basicConfig(level=logging.INFO) +logger = logging.getLogger(__name__) + def has_key(lists: list, key: str, value: any) -> bool: - # DEBUG: print(f"DEBUG: lists()={len(lists)},key='{key}',value[]='{type(value)}' - CALLED!") + logger.debug("lists()=%d,key='%s',value[]='%s' - CALLED!", len(lists), key, type(value)) + if not isinstance(lists, list): - raise ValueError(f"Parameter lists[]='{type(lists)}' is not 'list'") + raise ValueError(f"Parameter lists[]='{type(lists)}' is not of type 'list'") elif not isinstance(key, str): - raise ValueError(f"Parameter key[]='{type(key)}' is not 'str'") + raise ValueError(f"Parameter key[]='{type(key)}' is not of type 'str'") elif key == "": raise ValueError("Parameter 'key' is empty") has = False - # DEBUG: print(f"DEBUG: Checking lists()={len(lists)} ...") + logger.debug("Checking lists()=%d ...", len(lists)) for row in lists: - # DEBUG: print(f"DEBUG: row['{type(row)}']={row}") + logger.debug("row[%s]='%s", type(row), row) + if not isinstance(row, dict): - raise ValueError(f"row[]='{type(row)}' is not 'dict'") + raise ValueError(f"row[]='{type(row)}' is not of type 'dict'") elif not key in row: raise KeyError(f"Cannot find key='{key}'") elif row[key] == value: + logger.debug("row[%s][]='%s' matches value[]='%s'", key, type(row[key]), type(value)) has = True break - # DEBUG: print(f"DEBUG: has={has} - EXIT!") + logger.debug("has='%s' - EXIT!", has) return has