title: Error: Local variable referenced before assignment in python
body: <p>I have a python websocket client code </p>
  
  <pre><code>run_once1 = True
  run_once2 = False
  
  def on_message(ws, message):
  
      if 'Temp' in message:
          if run_once1 is True:
              #Run this code once
              print("Temp is present")
              run_once1 = False
              run_once2 = True
  
      else:
          if run_once2 is True:
              #Run this code once
              print("Temp is not present")     
              run_once1 = True
              run_once2 = False       
  
  def on_error(ws, error):
      print(error)
  
  def on_close(ws):
      print("CLOSE ")
  
  def on_open(ws):
      print("OPEN")
      msg = "&lt;MESSAGE&gt;"
      ws.send(msg)
  
  ws = websocket.WebSocketApp(URL, on_message= on_message, on_error=on_error, on_close=on_close)
  ws.on_open = on_open
  ws.run_forever()
  </code></pre>
  
  <p>So in the above code, I am opening a websocket and then whenever I receive a new message, <code>on_message()</code> function is called. Inside this function, I am looking for tag <code>Temp</code> in the message. If it is present, I just want to print that and run it once. Next when <code>Temp</code> is not present, I want to print it and also run that code just once. But the above code gives error:</p>
  
  <p><code>error from callback &lt;function on_message at 0x000001D35366D840&gt;: local variable 'run_once1' referenced before assignment</code></p>
  
  <p><code>error from callback &lt;function on_message at 0x000001D35366D840&gt;: local variable 'run_once2' referenced before assignment</code></p>
  
  <p>Where should I write these variable so that it do not give me this error.</p>
  
  <p>Thanks</p>