title: Remove lines that contain certain string
body: <p>I'm trying to read a text from a text file, read lines, delete lines that contain specific string (in this case 'bad' and 'naughty').
  The code I wrote goes like this:</p>
  
  <pre><code>infile = file('./oldfile.txt')
  
  newopen = open('./newfile.txt', 'w')
  for line in infile :
  
      if 'bad' in line:
          line = line.replace('.' , '')
      if 'naughty' in line:
          line = line.replace('.', '')
      else:
          newopen.write(line)
  
  newopen.close()
  </code></pre>
  
  <p>I wrote like this but it doesn't work out.</p>
  
  <p>One thing important is, if the content of the text was like this:</p>
  
  <pre><code>good baby
  bad boy
  good boy
  normal boy
  </code></pre>
  
  <p>I don't want the output to have empty lines.
  so not like:</p>
  
  <pre><code>good baby
  
  good boy
  normal boy
  </code></pre>
  
  <p>but like this:</p>
  
  <pre><code>good baby
  good boy
  normal boy
  </code></pre>
  
  <p>What should I edit from my code on the above?</p>