1from munch import Munch 2 3b = Munch() 4b.hello = 'world' 5assert b.hello == 'world' 6b['hello'] += "!" 7assert b.hello == 'world!' 8b.foo = Munch(lol=True) 9assert b.foo.lol is True 10assert b.foo is b['foo'] 11 12assert sorted(b.keys()) == ['foo', 'hello'] 13 14b.update({'ponies': 'are pretty!'}, hello=42) 15assert b == Munch({'ponies': 'are pretty!', 'foo': Munch({'lol': True}), 'hello': 42}) 16 17assert sorted([(k, b[k]) for k in b]) == [('foo', Munch({'lol': True})), ('hello', 42), ('ponies', 'are pretty!')] 18 19format_munch = Munch(knights='lolcats', ni='can haz') 20assert "The {knights} who say {ni}!".format(**format_munch) == 'The lolcats who say can haz!' 21