title: Python writing too much
body: <p>I've looked around the web and can't find an answer, sorry if I missed it.</p>
  
  <p>I'm trying to simply replace some lines in a file, do something with this modified file, then rewrite it to its original state. So I keep a copy of the base file, modify the one I need to do something with, then rewrite the base file into the modified one.</p>
  
  <p>Here's my code : </p>
  
  <pre><code>lines = open('fileToModify').readlines()
  for i, line in enumerate(lines[:]):
      if "STRING" in line:
          lines[i] = line.replace("STRING", sys.argv[1])
      if "STRING2" in line:
          lines[i] = line.replace("STRING2", sys.argv[2])
  pfile = open("fileToModify", "r+")
  pfile.seek(0)
  pfile.writelines(lines)
  pfile.seek(0)
  baseLines = open("baseFile").readlines()
  pfile.writelines(baseLines)
  pfile.close()
  </code></pre>
  
  <p>The problem is that when I rewrite the base file to the modified one, the last 2 chars of the base file are copied into a new line of the modified file. I don't know what I'm doing wrong, it seems really strange to me ... </p>
  
  <p>Also if there is a better way to achieve this purpose, I'm up to any suggestions.</p>
  
  <p>Thank's in advance !</p>