-
Notifications
You must be signed in to change notification settings - Fork 8
Open
Labels
enhancementNew feature or requestNew feature or requesthelp wantedExtra attention is neededExtra attention is neededwontfixThis will not be worked onThis will not be worked on
Description
Create a new utility method (or enhance init?) to convert nested dictionaries into nested CleverDicts, so that deeper levels can be accesses easily with "." notation. For example:
>>> d = CleverDict({"level1": {"level2A": "A", "level2B": "B"}})
>>> d.level1.level2B
'B'
>>> d
CleverDict({'level1': CleverDict({'level2A': 'A', 'level2B': 'B'}, _aliases={}, _vars={})}, _aliases={}, _vars={})
I'd also like to extend this functionality to attributes, which might be trickier. For example:
>>> ac1 = AnotherClass()
>>> ac2 = AnotherClass()
>>> ac1.level2 = "Level Two"
>>> ac2.level1 = "Level One"
>>> d = CleverDict(ac1, ac2)
>>> d.ac1.level2
"Level Two"
>>> d.ac2.level1
"Level One"
And the absolute ideal would be to handle any mixture of dictionaries and objects/attributes. For example:
>>> d = CleverDict({"First Item": {"level1": {"level2A": "A", "level2B": "B"}}},
ac1, {"Second Item": {"obj": ac2}}}
>>> d.First_Item.level1.level2A
"A"
>>> d.ac1.level2
"Level Two"
>>> d.Second_Item.obj.level1
"Level One"
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requesthelp wantedExtra attention is neededExtra attention is neededwontfixThis will not be worked onThis will not be worked on