title: Received "UnboundLocalError: local variable 'e' referenced before assignment" when the variable was initialized
body: <p><strong>[Community edit to give reproducible example:]</strong></p>
  
  <pre><code>def main():
      e = None
      print(locals())
      while not e:
          try:
              raise Exception
          except Exception as e:
              pass            
  
  main()
  </code></pre>
  
  <p>produces</p>
  
  <pre><code>~/coding$ python3.3 quiz2.py
  {'e': None}
  Traceback (most recent call last):
    File "quiz2.py", line 11, in &lt;module&gt;
      main()
    File "quiz2.py", line 5, in main
      while not e:
  UnboundLocalError: local variable 'e' referenced before assignment
  </code></pre>
  
  <hr>
  
  <p>[EDITED] to include a reproducible code</p>
  
  <p>I am trying to run a while-loop, and the condition I use is that the loop continues when the variable <code>e==None</code>. The relevant code is below:</p>
  
  <pre><code>    print("\nThe current score list contains the following people's scores: ")
      score_list = open("score_list.dat", "rb")
      score_name = []
      e = None
      while not e:
          try:
              score = pickle.load(score_list)
              name = pickle.load(score_list)
              score_name.append([score, name])
          except EOFError as e:
              pass            
      score_list_sorted=sorted(score_list)
      sort_list.close()
      for item in score_list_sorted:
          print("Score: ", item[0], "\t", item[1])
  </code></pre>
  
  <p>the complete code is here: <code>https://www.dropbox.com/s/llj5xwexzfsoppv/stats_quiz_feb24_2013.py</code></p>
  
  <p>The data file it requires (for the quiz to run) is in this link: <code>https://www.dropbox.com/s/70pbcb80kss2k9e/stats_quiz.dat</code></p>
  
  <p><code>main()</code> needs to be edited to use the proper data file address:</p>
  
  <p>The complete error message I received is below. This is weird because I initialized <code>e</code> right before the while-loop. I hope someone can help me resolve this problem. Thanks!</p>
  
  <pre><code>Traceback (most recent call last):
    File "&lt;pyshell#217&gt;", line 1, in &lt;module&gt;
      main()
    File "/Users/Dropbox/folder/stats_quiz_feb24_2013.py", line 83, in main
      while not e:
  UnboundLocalError: local variable 'e' referenced before assignment
  </code></pre>