python

We have a dictionary, and want to convert it to a an object with postfix notation (‘obj.name’).

Convert to an immutable object

Use collections.namedtuple.

>>> from collections import namedtuple
>>> data = {'id': 1, 'name': 'foo'}
>>> Obj = namedtuple('Obj', data.keys())
>>> obj = Obj(**data)
>>> obj.name
'foo'

Convert to a mutable object

Use types.SimpleNamespace.

>>> from types import SimpleNamespace
>>> data = {'id': 1, 'name': 'foo'}
>>> obj = SimpleNamespace(**data)
>>> obj.name
'foo'

See also: Convert a sequence to postfix notation