I have a nested dictionary that I want to convert to the following subclass I did:
class SubDict(dict):
def __getattr__(self, attr):
if attr in self.keys():
return self.get(attr)
And if I do, it works great for the base dict :
my_nested_dict = SubDict(my_nested_dict)
But I need the nested ones converted to SubDict too. How could I achieve that?
Thanks!
You need to recurse over the nested dictionaries and convert those recursively:
Have you looked into
collections.defaultdictat all? You can create a tree from scratch with that quite easily: