title: Replace carriage returns in list python
body: <p>I have a list of values and need to remove errant carriage returns whenever they occur in a list of values.</p>
  
  <p>the format of the file that I am looking to remove these in is as follows.</p>
  
  <pre><code>field1|field2|field3|field4|field5
  value 1|value 2|value 3|value 4|value 5
  value 1|value 2|value 3|value 4|value 5
  value 1|value 2|val
  ue 3|value 4|value 5
  value 1|value 2|value 3|va
  lue 4|value 5
  </code></pre>
  
  <p>I am looking to address a situation like the one above where there are errant carriage returns in the 3rd and 4th values for the last 2 rows of data.</p>
  
  <p>I have seen a few posts for how to address this but so far nothing has worked for this situation.  I have pasted the code I have attempted so far. </p>
  
  <pre><code>import os
  import sys
  
  filetoread = 'C:\temp\test.dat'
  filetowrite = 'C:\emp\test_updated.dat'
  
  '''
  Attempt 1
  '''
  with open(filetoread, "r+b") as inf:
      with open(filetowrite, "w") as fixed:
          for line in inf:
              fixed.write(line)
  
  
  '''
  Attempt 2
  '''           
  for line in filetoread:
      line = line.replace("\n", "")
  
  
  '''
  Attempt 3
  '''
  with open(filetoread, "r") as inf:
      for line in inf:
          if "\n" in line:
              line = line.replace("\n", "")
  </code></pre>