遍历文件不可避免地将大量内容缓冲-这是所有Python 2. *实现的一个已知问题。它可以按照您在Python 3.1中的预期工作,最终循环略有不同:
for line in proc.stdout: print(">>> " + str(line.rstrip()))
如果升级到Python 3.1是不切实际的(并且我知道通常是这样!),请换一种方式,以老式的方式编写循环-循环的以下版本确实可以在Python 2中实现。
:
while True: line = proc.stdout.readline() if not line: break print ">>> " + line.rstrip()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)