How to use dot notation for dict in python?
<p>I'm very new to python and I wish I could do <code>.</code> notation to access <code>dict</code> object in python. </p>

<p>Lets say I have <code>test</code> like this:</p>

<pre><code>&gt;&gt;&gt;test = dict()
&gt;&gt;&gt; test['name'] = 'value'
&gt;&gt;&gt; print(test['name'])
value
</code></pre>

<p>But I wish I could do <code>test.name</code> to get <code>value</code>. Infact I did it by overriding the <code>__getattr__</code> method in my class like this:</p>

<pre><code>class JuspayObject:

def __init__(self,response):
    self.__dict__['_response'] = response

def __getattr__(self,key):
    try:
        val = self._response[key]
        return val
    except KeyError,err:
        sys.stderr.write('Sorry no key matches')
</code></pre>

<p>and this works! when I do :</p>

<pre><code>test.name //I get value.
</code></pre>

<p>But the problem is when I just print <code>test</code> alone I get the error as:</p>

<pre><code>'Sorry no key matches'
</code></pre>

<p>why this happening!!!</p>

<p>Thanks in advance.</p>
