title: How to stop overwriting a file?
body: <p>My program takes data that has been created during the course of the program, and at the end the user has a choice to export this data to a .txt file or not. If I enter a value for the FileName that already exists, the program should ask the user if they would like to overwrite the current .txt file. During my code, if I enter the value that already exists, it overwrites this data instead of following the next line of code. I have seen other articles saying to use "a" for append, but I don't see how this would have any relevance for this program.</p>
  
  <p>(A temp file is already created earlier on in the program, and if the user chooses to export data, the file is simply renamed. If the user doesn't want to, it will delete the file.)</p>
  
  <pre><code>def export():
      fileName = input(FileNameText)
      exist = os.path.isfile(fileName)
      if exist == True:
          print("This file name already exists.")
          while True:
              try:
                  overWrite = input("Would you like to overwrite the file? Y = yes, N = no\n")
                  if overWrite == "Y":
                      break
                  if overWrite == "N":
                      export()
                  else:
                      invalidInput()
              except:
                  invalidInput()
          os.rename("temp.txt",fileName+".txt")
      if exist == False:
          os.remove("temp.txt")
  </code></pre>