Skip to content

Instantly share code, notes, and snippets.

@alfasin
Created December 2, 2015 18:27
class obj(object):
def __init__(self, d):
for a, b in d.items():
if isinstance(b, (list, tuple)):
setattr(self, a, [obj(x) if isinstance(x, dict) else x for x in b])
else:
setattr(self, a, obj(b) if isinstance(b, dict) else b)
d = {'a': 1, 'b': {'c': 2}, 'd': ["hi", {'foo': "bar"}]}
x = obj(d)
print x.a
print x.b.c
print x.d[1].foo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment