title: How to avoid overwriting a file in python?
body: <p>I am trying to make a program that will take the answers of what the user inputted and put it in a text document in Python 2.7.  I have the problem of when running the program again, the text document is overwritten and the previous data was deleted. So I was wondering how to avoid this problem. If this was already answered, please link the article. Thanks a bunch in advance! </p>
  
  <pre><code>import time
  import sys as LOL
  print 'Welcome to the database, enter -1 to exit.'
  time.sleep(1)
  files = open('c:/writing.txt','w')
  name = raw_input('Enter in your name... ')
  if name == '-1':
      LOL.exit()
  time.sleep(1)
  if len(name)&gt; 64 or len(name)&lt; 1:
      print 'Please enter a name that is between 1 and 64 characters!!'
  while len(name)&gt;64 or len(name)&lt;1:
      name = raw_input('Enter in your name... ')
      if name == '-1':
          LOL.exit()
      if len(name)&gt; 64 or len(name)&lt;1:
          print 'Please enter a name that is between 1 and 64 characters!!'
          time.sleep(1)
  time.sleep(1)
  age = int(raw_input('Enter in your age... '))
  if age == -1:
      LOL.exit()
  while age &gt; 125 or age &lt; 1:
      age = int(raw_input('Enter in your age... '))
      if name == '-1':
          LOL.exit()
      time.sleep(1)
      if age &gt; 125 or age &lt; 1:
          print 'Enter in a vaild age!'
  newedit = name + ' is %s years old.' %age
  files.write(newedit)
  files.close()
  </code></pre>