title: Python | How to make local variable global, after script execution
body: <p>Here is the code. What I need to do is find a way to make <code>i</code> global so that upon repeated executions the value of <code>i</code> will increment by 1 instead of being reset to 0 everytime. The code in <code>main</code> is from another script that I embed in 'main' in order to have the trace function work. This is all being done from Java.</p>
  
  <pre><code>from __future__ import nested_scopes
  import sys
  import time
  
  startTime = time.time()
  timeLimit = 5000
  def traceit(frame, event, arg):
  if event == "line": 
      elapsedTime = ((time.time() - startTime)*1000)
      if elapsedTime &gt; timeLimit:
           raise Exception, "The execution time has exceeded the time limit of " + str(timeLimit) + " milliseconds. Script will now terminate"
  return traceit
  
  sys.settrace(traceit)
  def main______():
      try:
          i+=1
      except NameError:
          i=1
  main______()
  </code></pre>