title: In place replacement of text in a file in Python
body: <p>I am using the following code to upload a file on server using FTP after editing it:</p>
  
  <pre><code>import fileinput
  
  file = open('example.php','rb+')
  
  for line in fileinput.input('example.php'):
      if 'Original' in line :
          file.write( line.replace('Original', 'Replacement'))
  
  file.close()    
  </code></pre>
  
  <p>There is one  thing, instead of replacing the text in its original place, the code adds the replaced text at the end and the text in original place is unchanged.</p>
  
  <p>Also, instead of just the replaced text, it prints out the whole line. Could anyone please tell me how to resolve these two errors?</p>