title: python global variable initialization in socket programming
body: <p>Using a socket programming library am creating a function and validating the same in every tick of the callback. so i declared a global variable initial in the top and checking that variable in the tick but am getting the below error: </p>
  
  <p>ERROR:websocket:error from callback >: local variable 'initial' referenced before assignment</p>
  
  <p>Seems on every call back the python global scope not getting initialized</p>
  
  <h2>(zeroconnecty.py)</h2>
  
  <pre><code>from kiteconnect import WebSocket
  
  kws = WebSocket("xxxx", "xxxx", "USERNAME")
  
  initial=True
  print "initial",initial
  
  #Callback for tick reception.
  def on_tick(tick, ws):
  
      if(initial):
          print "only execute if it called first time callback"
          initial=False
      else:
          print "all times except initial callback"
  
  
  #Callback for successful connection.
  def on_connect(ws):
  
      ws.subscribe([738561])
      ws.set_mode(ws.MODE_FULL, [738561])
  
  #Assign the callbacks.
  kws.on_tick = on_tick 
  kws.on_connect = on_connect
  
  #Infinite loop on the main thread. Nothing after this will run.
  #You have to use the pre-defined callbacks to manage subscriptions.
  kws.connect() 
  </code></pre>