Created
October 3, 2017 21:09
-
-
Save octaflop/1b12120e3f5ad0273107ead33fad67fc to your computer and use it in GitHub Desktop.
Convert a python dictionary to an object
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 asobj(object): | |
""" | |
Convert a python dictionary to an object accessible as attributes. | |
Args: | |
d: a python dictionary | |
Returns: | |
object: a python object with keys as attributes | |
""" | |
def __init__(self, d): | |
for key, val in d.iteritems(): | |
if isinstance(val, dict): | |
d[key] = asobj(val) | |
self.__dict__ = d |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment