title: Python Can't find string in file
body: <p>I started working on my game few days ago. I made system for loading(on start) and saving(on exit). On first loging in everything is fine but on second error(NameError: name 'strange' is not defined) showed up. Can someone help me to solve it please? I know that problem is in finding name in file becouse I tryed to put else statment after everything under</p>
  
  <pre><code>elif ab.read().find(a) != -1:    
  </code></pre>
  
  <p>and that what I put under else worked but it was just print so other required didn't worked under else.
  Here's my program:</p>
  
  <pre><code>import sys, random, time, re
  print("Welcome to game Special Travel Adventure!")
  def con(a, b):
      return a.lower() == b.lower()
  a = str(input("If you want to continue with game type your name here: "))
  ab = open("STAPlayers.txt", "r+")
  if ab.read().find(a) == -1:
      if ab.read() == "":
          ac = "Name:" + a + ":Strange:" + "0" + ":Courage:" + "0" + ":Skills:" + "0" + ":Money:" + "0" + ":Level:" + "0" + ":Deaths:" + "0"
          ab.write(ac)
          strange = 0 
          courage = 0
          skills = 0
          money = 0
          level = 0
          deaths = 0
      else:
          ac = "\nName:" + a + ":Strange:" + "0" + ":Courage:" + "0" + ":Skills:" + "0" + ":Money:" + "0" + ":Level:" + "0" + ":Deaths:" + "0"
          ab.write(ac)
          strange = 0 
          courage = 0
          skills = 0
          money = 0
          level = 0
          deaths = 0
  elif ab.read().find(a) != -1:
      readdd = ab.readlines()
      for line in readdd:
          if line.find(a) != -1:
              zm = line.split(":")
              zm.remove("Name")
              zm.remove("Strange")
              zm.remove("Courage")
              zm.remove("Skills")
              zm.remove("Money")
              zm.remove("Level")
              zm.remove("Deaths")
              strange = int(zm[1]) 
              courage = int(zm[2])
              skills = int(zm[3])
              money = int(zm[4])
              level = int(zm[5])
              deaths = int(zm[6])
  ab.close()
  def levelc():
      if courage and strange and skills == 1:
          level += 1
          return True
      if courage and strange and skills == 2:
          level += 1
          return True
      if courage and strange and skills == 3:
          level += 1
          return True
      if courage and strange and skills == 4:
          level += 1
          return True
      if courage and strange and skills == 5:
          level += 1
          return True
      else:
          return False
  b = input("Start Menu\nSelect: Start, Upgrades, Exit. ")
  while b != "dont save":
      if con(b, "Exit"):
          aj = open("STAPlayers.txt", "r")
          lines = aj.readlines()
          aj.close()
          aj = open("STAPlayers.txt", "w")
          jmj = "Name:" + a + ":Strange:" + str(strange) + ":Courage:" + str(courage) + ":Skills:" + str(skills) + ":Money:" + str(money) + ":Level:" + str(level) + ":Deaths:" + str(deaths)
          for linee in lines:
              if str(a) not in linee:
                  aj.write(linee)
              elif str(a) in linee:
                  jmjm = jmj + "\n"
                  aj.write(jmjm)
          aj.close()
          sys.exit()
          break
  </code></pre>
  
  <p>I know that problem is in finding name in file becouse I tryed to put else statment after everything under</p>
  
  <pre><code>elif ab.read().find(a) != -1:    
  </code></pre>
  
  <p>and that what I put under else worked but it was just print so other required didn't worked under else. Please help.</p>