Python How to use global verables and DRY
<p>So I have finally got my base class set up nicely and ready to build a class to test. However when I started buildign this I noticed that I had to repeat myself Lot with setting everything to global</p>

<p>the start() event is called to set up everything
Update() is called every tick (20 ticks a sec)</p>

<p>Is there a more efficient way to use global venerable then this.</p>

<pre><code>class BodyClass(BaseClass):
    def __init__(self, name):
        super().__init__(name)


    def Start(self):
        global i
        i = 0
        global d
        d = True
        global obj1
        obj1 = ChildClassA('Obj1')
        global obj2
        obj2 = ChildClassB('Obj2')
        global obj3
        obj3 = ChildClassC('Obj3')
        global obj4
        obj4 = ChildClassB('Obj4')
        global obj5
        obj5 = ChildClassB('Obj5')
        global obj6
        obj6 = ChildClassB('Obj6')

    def Update(self):


        global i
        global d
        global obj1
        global obj2
        global obj3
        global obj4
        global obj5
        global obj6

        print ("TYPE:", obj3.CType())
        i = i+ 1
        time.sleep(0.05)
        print("i: ", i)
        if i &gt;= 10:
            if d:
                print("UNLOADING")
                obj2.Unload()
                obj4.Unload()
                obj5.Unload()
                obj6.Unload()

                d=False
</code></pre>

<p>Don't use global variables. You're literally not using self at all. Move all your shared state to <code>self</code>. That's what it's for. Don't use global variables.</p>

python global-variables dry