Last active
September 23, 2019 00:49
-
-
Save TzuChiehHung/28af2a6687cae4ee6fb39ff24100e5c3 to your computer and use it in GitHub Desktop.
[Convert dictionary to attribute] convert dictionary to class attribute for easily using. #python
This file contains 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 DictToAttr: | |
def __init__(self, **entries): | |
for key, value in entries.items(): | |
value2 = (DictToAttr(**value) if isinstance(value, dict) else value) | |
self.__dict__[key] = value2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment