Python nested objects unable to retrieve value in function
<p>I am trying to build a tree structure that represents a parsed configuration file (the configuration file has a hierarchical structure to it).  I represented this as:</p>

<pre><code>class configContainer():

    treeDict = {}
    instances = {}

class configObject():

    def __init__(self, name, configLine, parent):
        self.name = name                # Assign to the line number to make unique
        self.parent = parent            
        self.children = []
        self.configLine = configLine    # Actual line of the configuration
        configContainer.instances[name] = self
</code></pre>

<p>The <code>configContainer</code> contains a set of objects. <code>configContainer.instances</code> uses a key of "line#" to map to the object. <code>treeDict</code> does a similar mapping, but with a different key (I create <code>treeDict</code> after the entire container is created).</p>

<p>I then try to reference two objects inside two different <code>configContainers</code>. This works fine from <code>__main__</code>.  But when I pass the two <code>configContainers</code> to a function, instances always returns objects from <code>configContainer2</code></p>

<pre><code>if __name__ == "__main__":


    f1 = open('rfile', 'r')
    configFile1 = f1.read()
    f1.close()

    configTree1 = parseConfig(configFile1)
    configTree1.treeDict = createTreeDict(configTree1)
    zObject1 = configTree1.instances["line10"]


    f2 = open('sfile', 'r')
    configFile2 = f2.read()
    f2.close()

    configTree2 = parseConfig(configFile2)
    configTree2.treeDict = createTreeDict(configTree2)
    zObject2 = configTree2.instances["line10"]

    print "\n\nFrom __main__"
    print "###########################"
    print configTree1
    print configTree2
    print zObject1
    print zObject2


    compareConfigurations(configTree1, configTree2)


def compareConfigurations(tmpTree1, tmpTree2):

    print "\n\nFrom compareConfigurations"
    print "###########################"
    print tmpTree1
    print tmpTree2
    zObject1 = tmpTree1.instances["line10"]
    zObject2 = tmpTree2.instances["line10"]
    print zObject1
    print zObject2
</code></pre>

<p>Result is:</p>

<pre><code>### From __main__

&lt;__main__.configContainer instance at 0xb77a34ec&gt;

&lt;__main__.configContainer instance at 0xb740a68c&gt;

&lt;__main__.configObject instance at 0xb740e3ac&gt;

&lt;__main__.configObject instance at 0xb7414bcc&gt;


### From compareConfigurations

&lt;__main__.configContainer instance at 0xb77a34ec&gt;

&lt;__main__.configContainer instance at 0xb740a68c&gt;

&lt;__main__.configObject instance at 0xb7414bcc&gt;

&lt;__main__.configObject instance at 0xb7414bcc&gt;
</code></pre>

<p>I can't figure out why I am always getting back the 0xb7414bcc object from inside <code>compareConfigurations</code>?</p>
