How can I call a Subclass object from a Superclass and is there a better way to do this? (Python 3)
<p>I am creating a game in python(3) and I have a main class with the game loop and a bunch of variables in it. I have a subclass of this to create "path" objects, and I need the variables from the main class. I also need to call the subclass from the main, superclass. Every time I call the subclass, it also calls the main classes <strong>init</strong> method to pass variables through. The problem is when this happens, it resets the values of all my variables in the main class.</p>

<pre><code>class Main:
    def __init__(self):
        foo = 0 
        sub1 = Sub()

    def foo_edit(self):
        self.foo += 5

    def main(self):
        sub2 = Sub()


class Sub(Main):
    def __init__(self):
        super(Sub, self).__init__()
        self.bar = 0

    def foo_edit(self):
        self.foo += 10
</code></pre>

<p>I've looked at many other similar questions, but none have given me the answer I need. I tried sub1 in my code(in the <strong>init</strong> function of main) and this creates a recursion loop error because the <strong>init</strong> functions call eachother forever. When I call it in the gameloop(or main in this example) it re initializes Main each time it is called, wiping the variables needed in Sub. Before I only had one instance of the "path" so I had no need of class, and had a function. Now that I need multiple "path" objects I am using a subclass of main to get the variables I need. </p>

<p>A solution to this problem that does or does not answer my question(calling a subclass from a superclass might be a bad idea) would be appreciated. Thanks in advance.</p>

<p>EDIT: I could pass the variables needed into the "Sub" class, however I need them to be updated so I would need some sort of update method to make sure the variables passed in are changed in Sub when they are in Main. This is easily doable, but I was wondering if there was easier/better way to do it.</p>