Error in the python script
<p>I have this simple python script where <code>myvar1</code> is accessible in <code>generate()</code> function but not in <code>copy()</code> function. Need help figuring out the error:</p>

<pre><code>#!/usr/bin/python

import os, time

def Test(tcid,descr,iterations,filsz):

        def setup():
                print "entering set up\n"
                global myvar1, myvar2

                myvar1 = 1.0
                myvar2 = os.getcwd()

        def generate():
                print "entering generate\n"
                print "in generate", myvar1, myvar2

        def copy():

           print "in copy", myvar1, myvar2
           myvar1 += 5.0



        setup()
        generate()

        for loopcount in range(5):
           loopcount = loopcount + 1
           copy()



if __name__ == "__main__":
        Test('test','simple test',2,10)
</code></pre>

<p>Error:</p>

<p>Traceback (most recent call last):
  File "./pyerror.py", line 35, in 
    Test('test','simple test',2,10)
  File "./pyerror.py", line 30, in Test
    copy()
  File "./pyerror.py", line 20, in copy
    print "in copy", myvar1, myvar2
UnboundLocalError: local variable 'myvar1' referenced before assignment</p>
