re-using the variable in a function in a class in python
<p>I will try to explain the problem I am facing with a small piece of code:</p>

<pre><code>class MyHandler(PatternMatchingEventHandler):
    patterns = ["*.csv","*.processing", "*.transforming","*.loading"]

    def process(self, event):
        eventFileName = event.src_path
        eventType = event.event_type
        if eventType == 'moved':
            eventFileName = event.dest_path
        fileNameWithPath, fileExtension = os.path.splitext(eventFileName)

        if fileExtension == '.processing': 
            # Here some function is called to do something, and then appends ".loading" to the file name
            testVariable = 75.3
        if fileExtension == '.loading':
            print testVariable
    def on_moved(self, event):
        self.process(event)

    def on_created(self, event):
        self.process(event)

if __name__ == '__main__':
    observer = Observer()
    observer.schedule(MyHandler(), path='.')
    observer.start()

    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        observer.stop()

    observer.join()
</code></pre>

<p>When I try to do the above I am getting this error: <code>global name 'testVariable' is not defined</code> which kinda makes sense but how do I make the above work? I tried to define "testVariable" globally and initiated to 0 and tried using it the way I showed in above code but it did not work as well.
I also tried initiating testVariable as <code>testVariable=0</code> inside the class (right after "patterns = ....." line but I got this error: <code>local variable "testVariable" referenced before assignment</code> pointing towards <code>print testVariable</code>. So that didnot work as well.</p>