Feature Request: default to an empty dict for missing keys
ma-sadeghi opened this issue · 3 comments
ma-sadeghi commented
It'd be nice if any missing key defaults to an empty dict (to reduce boilerplate in some cases).
cdgriffith commented
I think what you want then is just default_box=True
https://github.com/cdgriffith/Box/wiki/Types-of-Boxes#default-box
ma-sadeghi commented
@cdgriffith Thank you so much, that's exactly what I wanted! Also, thank you for creating this great package!
ma-sadeghi commented
@cdgriffith One more thing: I just noticed that when default_box=True
, as soon as a non-existent key is accessed, it gets created, even if nothing is assigned to it:
>>> x = Box(default_box=True)
>>> x
Box({})
>>> x.a
Box({})
>>> x
Box({'a': {}})
I was expecting that this only happens if I do something like: x.a = SOMETHING
. Is this something that can be achieved? Thanks!