Î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>The <code>__init__</code> method of any class is called once you create an instance of the class. You can't call it manually to instantiate the class, but use the class name.</p>

<p>Also, you are not really initializing a class that inherits it's methods and properties from <code>dict</code>. You need to use <a href="https://docs.python.org/2/library/functions.html#super" rel="nofollow"><code>super</code></a> for that. Also, this is a case where calling <code>__init__</code> makes actual sense.</p>

<pre><code>class fileInfo(dict):
    def __init__(self, name, typ, size = 1):
        super(fileInfo, self).__init__()

        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)

file_info = fileInfo("file-name", "txt", 100)

print file_info["name"]
</code></pre>

<p>Output:</p>

<pre><code>file-name.txt
</code></pre>

python dictionary initialization