Skip to content

Instantly share code, notes, and snippets.

@curzona
Created March 8, 2014 17:43
Show Gist options
  • Save curzona/9435711 to your computer and use it in GitHub Desktop.
Save curzona/9435711 to your computer and use it in GitHub Desktop.
Deeply convert dictionary to object(s)
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