title: Replace multiple newlines with single newlines during reading file
body: <p>I have the next code which reads from multiple files, parses obtained lines and prints the result:</p>
  <pre><code>import os
  import re
  
  files=[]
  pars=[]
  
  for i in os.listdir('path_to_dir_with_files'):
      files.append(i)
  
  for f in files:
      with open('path_to_dir_with_files'+str(f), 'r') as a:
         pars.append(re.sub('someword=|\,.*|\#.*','',a.read()))
  
  for k in pars:
     print k
  </code></pre>
  <p>But I have problem with multiple new lines in output:</p>
  <pre><code>test1
  
  
  test2
  </code></pre>
  <p>Instead of it I want to obtain the next result without empty lines in output:</p>
  <pre><code> test1
   test2
  </code></pre>
  <p>and so on.</p>
  <p>I tried playing with regexp:</p>
  <pre><code>pars.append(re.sub('someword=|\,.*|\#.*|^\n$','',a.read()))
  </code></pre>
  <p>But it doesn't work. Also I tried using strip() and rstrip() including replace. It also doesn't work.</p>