Convert dict to object

Elegant way to convert a normal Python dict with some nested dicts to an object

class Struct:
    def __init__(self, **entries):
        self.__dict__.update(entries)

Then, you can use

> args = {'a': 1, 'b': 2}
> s = Struct(**args)
> s
< __main__.Struct instance at 0x01D6A738 >
> s.a
1
> s.b
2

Related Readings