title: Copy a file line by line in python
body: <p>I am writing a python program to copy a file line by line into a new file. The code I have is below in which I am using a loop to copy the file line by line. </p>
  
  <p>However since the number of lines in the file may change, is there a way to copy a file line by line in python without using a loop which relies on numbers, and instead relies on the something like the EOF character to terminate the loop?</p>
  
  <pre><code>import os
  import sys
  
  i = 0
  f = open("C:\\Users\\jgr208\\Desktop\\research_12\\sap\\beam_springs.$2k","r")
  copy = open("C:\\Users\\jgr208\\Desktop\\research_12\\sap\\copy.$2k","wt")
  #loop that copies file line by line and terminates loop when i reaches 10
  while i &lt; 10:
       line = f.readline()
       copy.write(str(line))
       i = i +1
  f.close()
  copy.close()
  </code></pre>