3 ms·
Almost, he is also converting ordinary dicts that get added as items to his own Dict class to enable you to keep using this syntax further down the tree, so you
by zb 12y ago
Almost, he is also converting ordinary dicts that get added as items to his own Dict class to enable you to keep using this syntax further down the tree, so you'd need a small wrapper around __setitem__.
But yes, the idea of storing everything twice (once as an item and once as an attribute) just so you can unconditionally add defaults in __getattr__ is… bizarre and will break things horribly as soon as you accidentally do something like:
myDict['get'] = 'foo'
- deleted 12y ago[deleted]
- tyrion 12y ago> Almost, he is also converting ordinary dicts that get added as items to his own Dict class You are right I dind't notice that before. But looking at the code it seems that the only permitted values are dict and str?! > But yes, the idea of storing everything twice (once as an item and once as an attribute) I don't get that, you don't store things twice and nothing breaks, at least with the example code I wrote above. Try: >>> a=D() >>> a.lol = 2 >>> a['get'] = 'foo' >>> a {'get': 'foo', 'lol': 1} >>> vars(a) {}