Python equivalent to C-like assignment in conditional
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/7780998/assignment-condition-in-python-while-loop">Assignment Condition in Python While Loop</a>  </p>
</blockquote>



<p>What's the equivalent of this:</p>

<pre><code>while (line = p.stdout.readline()) != '':
    ...
</code></pre>

<p>in Python?</p>

<p>I don't like having to do this:</p>

<pre><code>line = p.stdout.readline()
while line != '':
    sys.stdout.write(line)
    line = p.stdout.readline()
</code></pre>

<p>Although I've been using the latter for years... I suspect there is no alternative. I thought <code>p.stdout</code> supported iteration, like</p>

<pre><code>for line in p.stdout:
    sys.stdout.write(line)
</code></pre>

<p>but unfortunately it doesn't, unlike the handle returned from <code>open()</code> for example.</p>

<p><strong>Edit:</strong> Sorry, I was wrong, it does support it, the problem is that I can't get it out right away like I can with <code>p.stdout.readline()</code>. Adding <code>sys.stdout.flush()</code> doesn't seem to help, so it must be getting buffered inside <code>p.stdout</code>.</p>
