get_item#

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

Given a path, return it’s value if it exists, or default value if missing. May also perform a search whether an item key exists and then returns the value or a list of values for multiple occurences of the key – optionally returns the full path(s) in addition to its value(s).

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) – 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) – Only applies if full_path=False. Default False. If True, returns an additional list of paths to the item(s) that match key.

  • default (None or object, default None) – The value to return if the path or item does not exist.

Examples

>>> dict = {'To' : {'be' : True}}
>>> dict_browser = DictionaryTreeBrowser(dict)
>>> dict_browser.get_item('To')
└── be = True
>>> dict_browser.get_item('To.be')
True
>>> dict_browser.get_item('To.be.or', 'default_value')
'default_value'
>>> dict_browser.get_item('be', full_path=False)
True