Types#
- brainmaze_utils.types.DicToObj(d)#
Converts dictionary into object where, keys - converts keys into attributes
- brainmaze_utils.types.DictToObjDict(d)#
Converts dictionary into object where, keys - converts keys into attributes
- class brainmaze_utils.types.ObjDict(VT_={})#
Dictionary which you can access a) as a dict; b) as a struct with attributes. Can use both foo adding and deleting attributes resp items. Inherits from dict
Missing keys are created on access (auto-vivification), both as items and as attributes, so nested structures can be built directly:
d = ObjDict() d.cfg.sub = 3 # {'cfg': {'sub': 3}} d['a']['b'] = 1 # {'cfg': ..., 'a': {'b': 1}}
A consequence (unchanged from v2.0.0): reading a missing public attribute creates it as an empty
ObjDict, sohasattr(d, 'x')is alwaysTruefor public names and creates'x'; test membership with'x' in dinstead.Names starting with an underscore (including dunders such as
__deepcopy__) are never auto-created; reading a missing one raisesAttributeError.Note
Changed after v2.0.0: Dunder lookups used to auto-create keys too, so
copy.deepcopy(),copyandpickleof anObjDictfailed ('ObjDict' object is not callable) and protocol probes (__array__,_repr_html_, …) added junk keys.
- brainmaze_utils.types.ObjDictToDict(d)#
Converts dictionary into object where, keys - converts keys into attributes
- class brainmaze_utils.types.TwoWayDict(d=None)#