[docs]classdotdict(dict):""" A dictionary supporting dot notation. This class extends the built-in `dict` type by adding support for accessing items using dot notation (e.g. `dotdict.a.b.c`) instead of square bracket notation (e.g. `dotdict['a']['b']['c']`). The class also provides a `lookup` method for looking up a value in a nested dictionary structure using a dot-separated path (e.g. "a.b.c"). Examples: >>> d = dotdict({'a': {'b': {'c': 1}}}) >>> d.a.b.c 1 >>> d.lookup('a.b.c') 1 """__getattr__=dict.get__setattr__=dict.__setitem____delattr__=dict.__delitem__
[docs]deflookup(self,dotkey:str)->Any:""" Look up a value in a nested dictionary structure using a dot-separated path. Args: dotkey: A dot-separated path to the value, e.g. "a.b.c". Returns: The value at the specified path. Raises: KeyError: If the specified path does not exist in the dictionary. """path=list(reversed(dotkey.split(".")))v=selfwhilepath:key=path.pop()ifisinstance(v,dict):v=v[key]elifisinstance(v,list):v=v[int(key)]else:raiseKeyError(key)returnv