title: Python - Only last line is saved to file
body: <p>I'm trying to output the result of my script into a text file. The script is working fine, the only problem is when results are saved into the text file (output.txt), only last line is being saved,not the whole thing? I'm not sure what I'm doing wrong here. any suggestions will be appreciated.</p>
  
  <p>Cheer!</p>
  
  <pre><code>        try:
  
              if 'notavailable' not in requests.get('url' + str(service) + '&amp;username=' + str(username), headers={'X-Requested-With': 'XMLHttpRequest'}).text:
                  result = service + '\t' + " &gt; " + username + " &gt; " 'Available'
                  print  result
                  f = open("output.txt", "w")              
                  f.write(result + "\n")
                  f.close()
  
              else:
                  print service + '\t' + " &gt; " + username + " &gt; " 'Not Available'
  
          except Exception as e:
              print e
  </code></pre>