has_item#

DictionaryTreeBrowser.has_item(item_path, default=None, full_path=True, wild=False, return_path=False)#

Given a path, return True if it exists. May also perform a search whether an item exists and optionally returns the full path instead of boolean value.

The nodes of the path are separated using periods.

Parameters:
  • item_path (str) – A string describing the path with each item separated by full stops (periods).

  • full_path (bool, default True) – If True, the full path to the item has to be given. If False, a search for the item key is performed (can include additional nodes preceding they key separated by full stops).

  • wild (bool, default True) – Only applies if full_path=False. If True, searches for any items where item matches a substring of the item key (case insensitive). Default is False.

  • return_path (bool, default False) – Only applies if full_path=False. If False, a boolean value is returned. If True, the full path to the item is returned, a list of paths for multiple matches, or default value if it does not exist.

  • default – The value to return for path if the item does not exist (default is None).

Examples

>>> dict = {'To' : {'be' : True}}
>>> dict_browser = DictionaryTreeBrowser(dict)
>>> dict_browser.has_item('To')
True
>>> dict_browser.has_item('To.be')
True
>>> dict_browser.has_item('To.be.or')
False
>>> dict_browser.has_item('be', full_path=False)
True
>>> dict_browser.has_item('be', full_path=False, return_path=True)
'To.be'