title: Error whilst trying to delete string from a 'txt' file it just deletes everything. - Contacts list program
body: <p>I'm creating a Contact list/book program which can create new contacts for you. Save them in a 'txt' file. List all contacts, and delete existing contacts. Well sort of. In my delete function there is an error which happens and I can't quite tell why?. There isn't a error prompted on the shell when running. It's meant to ask the user which contact they want to delete, find what the user said in the 'txt' file. Then delete it. It can find it easily, however it just deletes everything.</p>
  
  <p>I've tried various methods of doing this but nothing works?</p>
  
  <pre><code>import os, time, random, sys, pyautogui
  
  
  #function for creating a new contact.
  def new_contact():
      os.system('cls')
  
  
      name = str(input("Clients name?\n:"))
  
      name = name + " -"
  
      info = str(input("Info about the client?\n:"))
  
      #starts formatting clients name and info for injection into file.
  
      total = "\n\n"
      total = total + name
      total = total + " "
      total = total + info
      total = total + "\n"
      #Injects info into file.
  
  
      with open("DATA.txt", "a") as file:
  
          file.write(str(total))
          file.close
  
      main()
  
  #function for listing ALL contacts made.
  def list():
      os.system('cls')
  
  
  
      file = open("DATA.txt", "r")
      read = file.read()
      file.close
  
  
      #detects whether there are any contacts at all. If there are none the only str in the file is "Clients:"
      if read == "Clients:":
          op = str(input("You havn't made any contacts yet..\nDo you wish to make one?\n:"))
  
  
          if op == "y":
              new_contact()
  
  
          else:
              main()
  
      else:
          print (read)
          os.system('pause')
          main()
  
  
  #Function for deleting contact
  def delete_contact():
      os.system('cls')
  
  
      file = open("DATA.txt", "r")
      read = file.read()
      file.close
  
  
      #detects whether there are any contacts at all. If there are none the only str in the file is "Clients:"
      if read == "Clients:":
          op = str(input("You havn't made any contacts yet..\nDo you wish to make one?\n:"))
  
  
          if op == "y":
              new_contact()
  
  
          else:
              main()
  
  
      else:
          #tries to delete whatever was inputted by the user.
          file = open("DATA.txt", "r")
          read = file.read()
          file.close
  
  
          print (read, "\n")
  
  
          op = input("copy the Clients name and information you wish to delete\n:")
  
  
          file = open("DATA.txt", "w")
          var = read.replace((op), "")
          file.write(var)
          file.close
          os.system('pause')
          main()
  
          #with open("DATA.txt") as f:
              #reptext=f.read().replace(op, '')
  
  
          #with open("DATA.txt", "w") as f:
              #f.write(reptext)
              #main()
  
  
  main()
  
  </code></pre>
  
  <p>It is expected to delete whatever the user inputs as the variable <code>op</code> from the text file however it just deletes everything. It works by making everything inside the text file a <code>str</code>, replacing what the user inputted in the <code>str</code> with a <code></code>. However, it just replaces everything in the file with <code></code> (nothing).</p>
  
  <p>Here is what is in the .txt file:</p>
  
  <pre><code>Clients:
  
  Erich - The developer
  
  Bob - the test dummy.
  </code></pre>