title: Writing to a file in a for loop only writes the last value
body: <pre><code>text_file = open(&quot;new.txt&quot;, &quot;r&quot;)
  lines = text_file.readlines()
  
  for line in lines:
          var1, var2 = line.split(&quot;,&quot;);
          myfile = open('xyz.txt', 'w')
          myfile.writelines(var1)
          myfile.close()
  
  text_file.close()
  </code></pre>
  <p>I have 10 lines of text in new.txt like <code>Adam:8154</code>,
  <code>George:5234</code>, and so on. Now I want a text file which contains only the names. <code>xyz.txt</code> must contain <code>Adam</code>, <code>George</code>, and so on. The above code leaves me with the 10th name only.</p>
  <p>How to have all the 10 names in a single text file?</p>