Înitialising dictionary like class
<pre><code>class fileInfo(dict):
    def __init__(self, name, typ, size = 1):
        self = {}
        self["name"] = name
        self["type"] = typ
        self["size"] = size

    def __getitem__(self, key):
        if key == "name":
            return dict.__getitem__(self, "name")+ "." + dict.__getitem__(self, "type")
        return dict.__getitem__(self, key)
</code></pre>

<p>I have created this class, but I have problems with the <strong>init</strong> function.
When I try to initialize an object of this class, the <strong>init</strong> function returns me an empty dictionary.</p>

<p>What am I not understanding as far as the initialization function is concerned?</p>

<p>This line doesn't do what you think it does:</p>

<pre><code>    self = {}
</code></pre>

<p>That line creates a new object of type <code>dict</code>, and binds the local name <code>self</code> to it. This is wholly unrelated to the previous value of <code>self</code>, which is lost. And, since <code>self</code> is a local variable, the object created by this line will be marked for deletion when <code>__init__()</code> returns.</p>

<p>Try this instead:</p>

<pre><code>super(fileInfo, self).__init__()
</code></pre>

<p>This neither creates nor destroys any objects, but modifies the object referred to by <code>self</code>.</p>

<p>Reference:</p>

<ul>
<li><a href="http://stackoverflow.com/questions/576169/understanding-python-super-with-init-methods">Understanding Python super() with __init__() methods</a></li>
<li><a href="https://docs.python.org/2/reference/datamodel.html" rel="nofollow">https://docs.python.org/2/reference/datamodel.html</a></li>
</ul>

python dictionary initialization