Created
May 20, 2019 10:45
-
-
Save kkroesch/cfd017e6ec5b4af42fd9a49fd3370917 to your computer and use it in GitHub Desktop.
Wrap dictionary in namespace to access values wit dot notation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class NestedNamespace(SimpleNamespace): | |
| """ Wrapping dictionaries in namespace to access it with dot notation. """ | |
| def __init__(self, dictionary, **kwargs): | |
| super().__init__(**kwargs) | |
| for key, value in dictionary.items(): | |
| if isinstance(value, dict): | |
| self.__setattr__(key, NestedNamespace(value)) | |
| else: | |
| self.__setattr__(key, value) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment