title: Difference between iterating over a file-like and calling readline
body: <p>I always thought iterating over a file-like in Python would be equivalent to calling its <code>readline</code> method in a loop, but today I found a situation where that is not true. Specifically, I have a <code>Popen</code>'d process <code>p</code> where</p>
  
  <pre><code>list(itertools.takewhile(lambda x: x != "\n",
                           p.stdout))
  </code></pre>
  
  <p>hangs (presumably because <code>p</code> waits for input; both <code>stdin</code> and <code>stdout</code> are pipes to my Python process), while the following works:</p>
  
  <pre><code>list(itertools.takewhile(lambda x: x != "\n",
                           iter(p.stdout.readline, "")))
  </code></pre>
  
  <p>Can someone explain the difference?</p>