title: python loop over subprocess.check_output by line
body: <p>I need to loop over the output of a command. I thought I'd use <code>subprocess.check_output</code>, now I have two problems.</p>
  
  <p>Here's a file:</p>
  
  <pre><code>foo
  bar
  </code></pre>
  
  <p>Here's my python script:</p>
  
  <pre><code>import subprocess
  
  for line in subprocess.check_output(['cat', 'foo']):
    print "%r" % line
  </code></pre>
  
  <p>And here's what I get:</p>
  
  <pre><code>$ python subp.py 
  'f'
  'o'
  'o'
  '\n'
  'b'
  'a'
  'r'
  '\n'
  </code></pre>
  
  <p>I expect:</p>
  
  <pre><code>$ python subp.py
  'foo\n'
  'bar\n'
  </code></pre>