title: Python global name not defined in first function, but is in second one
body: <p>I am encountering a strange problem under python 2.7.10, here is the relevant part of my code:</p>
  <pre><code>...
  
  #is called whenever the reinitscore() is called, and if the if statement is correct
  def calculateWinner(d):
      scores = {}
      high_score = 0
  
      for key, value in d.items():
          try:
              scores[value].append(key)
          except KeyError:
              scores[value] = [key]
          if value &gt; high_score:
              high_score = value
      results = scores[high_score]
  
      if len(results) == 1:
          print results[0]
          stelnet.send(results[0])
          return results[0]
      else:
          print 'TIE'
          return 'TIE', results
  
  #is called once, then every 5 seconds automatically with threading
  def reinitScore():
      threading.Timer(5, reinitScore).start()
      global leftKeyCounter
      global rightKeyCounter
      global frontKeyCounter
      global backKeyCounter
  
      values = {'left' : leftKeyCounter, 'right' : rightKeyCounter, 'front' : frontKeyCounter, 'back' : backKeyCounter}
  
      if (leftKeyCounter != 0 or rightKeyCounter != 0 or frontKeyCounter != 0 or backKeyCounter != 0):
          calculateWinner(values)
          leftKeyCounter = 0
          rightKeyCounter = 0
          frontKeyCounter = 0
          backKeyCounter = 0
          print &quot;back to 0&quot;
      else:
          stelnet.send(&quot;test&quot;)
  
  if __name__ == &quot;__main__&quot;:
      if(len(sys.argv) &lt; 3):
          print 'Usage : python telnet.py hostname port'
          sys.exit()
       
      host = sys.argv[1]
      port = int(sys.argv[2])
       
      stelnet = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
      stelnet.settimeout(2)
       
      # connect to remote host
      try:
          stelnet.connect((host, port))
      except:
          print 'Unable to connect'
          sys.exit()
  
  ...
  
  while 1:
      socket_list = [sys.stdin, stelnet]
       
      # Get the list sockets which are readable
      read_sockets, write_sockets, error_sockets = select.select(socket_list , [], [])
       
      for sock in read_sockets:
          #incoming message from remote server
          if sock == stelnet:
              data = sock.recv(4096)
              if not data:
                  print 'Connection closed'
                  sys.exit()
              else:
                  #print data
                  sys.stdout.write(data)
           
          #user entered a message
          else:
              msg = sys.stdin.readline()
              stelnet.send(msg)
  </code></pre>
  <p>So what is happening here : calculateWinner() is called by the reinitScore, and send via telnet connection a result. there is no problem with the telnet sending in the calculateWinner() function, but when I want to use the stelnet.send() in reinitScore() he returns this</p>
  <h3>NameError: global name 'stelnet' is not defined</h3>
  <p>It is very strange, that I can use stelnet.send in a function, just next to each other, and not in another one...</p>
  <p>Also, my python is constantly giving me the</p>
  <h3>unindentend error</h3>
  <p>which is very annoying, because I only use tabs, and not any spaces, he even forces me to unindent parts (see end of reinitScore()) to accept running the code ...</p>
  <p>I am using Sublime Text (changed to Brackets because of the well known &quot;sublime&quot; problem with invisible characters, but doesn't change anything) under macosx ...</p>