擅长:python、mysql、java
<p>您不必亲自将流/文件拆分成行。只是重复:</p>
<pre><code>for ln in f:
# work on line in ln
</code></pre>
<p>对于文件(使用open()for file())和管道(使用Popen),这应该同样有效。使用popen对象的<code>stdout</code>属性访问连接到子进程stdout的管道</p>
<p><strong>示例</strong></p>
<pre><code>from subprocess import Popen, PIPE
pp = Popen('dir', shell=True, stdout=PIPE)
for ln in pp.stdout:
print '#',ln
</code></pre>