title: Add a char to the beginning and end of each line in a file
body: <p>I have a text file that each line contains exactly one word. I want update the file by attaching a char to the beginning and end of each word in each line. Here is my code in Python:</p>
  
  <pre><code>appendText='_'
  names=open("name.txt",'r')
  updatedNames=open("name2.txt",'a')
  for name in names:
    updatedNames.write(appendText+name+appendText)
  updatedNames.close()
  </code></pre>
  
  <p>But the problem is this code add the <code>_</code> to the end of line after the <code>\n</code> char. In other words, the output looks like this:</p>
  
  <pre><code>_Name
  _
  </code></pre>
  
  <p><code>_Name</code> followed by an <code>enter</code> and then in the next line there another <code>_</code>. I want to both <code>_</code> to be in the same line:</p>
  
  <pre><code>_Name_
  </code></pre>