Created
July 24, 2017 04:59
-
-
Save wonderbeyond/0bd7a5fd3768d1c5ff686f69b110dd13 to your computer and use it in GitHub Desktop.
python dict to object view
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 objectview(object): | |
"""Convert dict(or parameters of dict) to object view | |
See also: | |
- https://goodcode.io/articles/python-dict-object/ | |
- https://stackoverflow.com/questions/1305532/convert-python-dict-to-object | |
>>> o = objectview({'a': 1, 'b': 2}) | |
>>> o.a, o.b | |
(1, 2) | |
>>> o = objectview(a=1, b=2) | |
>>> o.a, o.b | |
(1, 2) | |
""" | |
def __init__(self, *args, **kwargs): | |
d = dict(*args, **kwargs) | |
self.__dict__ = d |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment