Created
March 8, 2014 17:43
-
-
Save curzona/9435711 to your computer and use it in GitHub Desktop.
Deeply convert dictionary to object(s)
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 Struct: | |
def __init__(self, **entries): | |
for k, v in entries.items(): | |
if isinstance(v, dict): | |
entries[k] = Struct(**v) | |
self.__dict__.update(entries) | |
d = {'a':{'b':1, 'c':2}, 'd':1} | |
struct = Struct(**d) | |
print struct.a.b |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment