def dict2obj(d):
if isinstance(d, (Mapping, list, tuple)):<EOL><INDENT>try:<EOL><INDENT>d = dict(d)<EOL><DEDENT>except (ValueError, TypeError):<EOL><INDENT>return d<EOL><DEDENT><DEDENT>else:<EOL><INDENT>return d<EOL><DEDENT>obj = Object()<EOL>for k, v in viewitems(d):<EOL><INDENT>obj.__dict__[k] = dict2obj(v)<EOL><DEDENT>return obj<EOL>
Convert a dict to an object or namespace


    >>> d = {'a': 1, 'b': {'c': 2}, 'd': ["hi", {'foo': "bar"}]}
    >>> obj = dict2obj(d)
    >>> obj.b.c
    2
    >>> obj.d
    ['hi', {'foo': 'bar'}]
    >>> d = {'a': 1, 'b': {'c': 2}, 'd': [("hi", {'foo': "bar"})]}
    >>> obj = dict2obj(d)
    >>> obj.d.hi.foo
    'bar'