Skip to content

Instantly share code, notes, and snippets.

@TzuChiehHung
Last active September 23, 2019 00:49
Show Gist options
  • Save TzuChiehHung/28af2a6687cae4ee6fb39ff24100e5c3 to your computer and use it in GitHub Desktop.
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
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