cdgriffith / cdgriffith/Box

Create subkeys with dots as needed

Open
#214 3 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Python
Stars
2.8k
Forks
135
PR merge metrics
No merged PRs in 30d

Description

Hey,

I noticed this line in the docs:
```
Be aware, if those sub boxes didn't exist as planned, a new key with that value would be created instead
```
So if i do:
```
In [1]: from box import Box

In [2]: b = Box(box_dots=True)

In [3]: b['a.c'] = 123

In [4]: b
Out[4]:

In [5]: b.a.c
---------------------------------------------------------------------------
BoxKeyError Traceback (most recent call last)
in
----> 1 b.a.c

~/python3.7/site-packages/box/box.py in __getattr__(self, item)
488 if self._box_config["default_box"]:
489 return self.__get_default(item, attr=True)
--> 490 raise BoxKeyError(str(err)) from None
491 return value
492

BoxKeyError: "'Box' object has no attribute 'a'"
```

Is there a way to make it so that it recursively makes boxes as needed to make it to the final key?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.