title: Python - Trying to truncate, write to and then copy the written-to file to another file
body: <p>This is the Python code I have written for this purpose:</p>
  
  <pre><code>from sys import argv
  from os.path import exists
  
  script, filenamefrom, filenameto = argv
  
  print "We're going to erase %r." % filenamefrom
  print "If you don't want that, hit CTRL-C (^C)."
  print "If you do want that, hit RETURN."
  
  raw_input("?")
  
  print "Opening the file..."
  target = open(filenamefrom,'w+')
  
  print "Truncating the file. Goodbye!"
  target.truncate()
  
  print "Now I'm going to ask you for three lines."
  
  line1 = raw_input("line 1: ")
  line2 = raw_input("line 2: ")
  line3 = raw_input("line 3: ")
  
  print "I'm going to write these to the file."
  
  target.write('%r\n%r\n%r\n' % (line1, line2, line3))
  
  print "Now we are going to copy %r to %r!" % (filenamefrom, filenameto)
  
  
  
  readdata = target.read()
  openfilenameto = open(filenameto,'w+')
  openfilenameto.write(readdata)
  
  
  print "And finally, we close it."
  
  openfilenameto.close()
  target.close()
  </code></pre>
  
  <p>Now when I run this in Powershell, this is what comes up:</p>
  
  <pre><code>We're going to erase 'test.txt'.
  If you don't want that, hit CTRL-C (^C).
  If you do want that, hit RETURN.
  ?
  Opening the file...
  Truncating the file. Goodbye!
  Now I'm going to ask you for three lines.
  line 1: h
  line 2: h
  line 3: h
  I'm going to write these to the file.
  Now we are going to copy 'test.txt' to 'test4.txt'!
  And finally, we close it.
  </code></pre>
  
  <p>However - once I run:</p>
  
  <pre><code>cat test4.txt
  </code></pre>
  
  <p>In Windows Powershell, this is what it outputs - nothing after the following line, although that empty space goes down the Powershell page 34 lines after the following line:</p>
  
  <pre><code>PS C:\python27&gt; cat test4.txt
  </code></pre>
  
  <p>I have tried changing the file mode modules between 'r+' and 'w+' throughout the Python code, but that doesn't work. </p>
  
  <p>Also - I know this is annoying and repetitive code, but I am quite new to this and am still building my skills in shortening code. Apologies for that and I appreciate the patience of any of you who may reply. </p>
  
  <p>Thanks.  </p>