这是我的功能
def f(task_list):
results = []
for task_id in task_list:
results.append(work(task_id))
print len(results) # show the progress
return results
我在ipython中使用execfile()来运行这个函数, 但似乎显示了进展 直到整个功能结束
======================= 我再试一次,现在看来还好......
答案 0 :(得分:0)
尝试强制刷新标准输出:
import sys
def f(task_list):
results = []
for task_id in task_list:
results.append(work(task_id))
print len(results) # show the progress
sys.stdout.flush() # this will force the system to display what is in the stdout queue
return results
答案 1 :(得分:0)
在python解释器中,可以使用-u
选项关闭输出的缓冲(虽然此选项在ipython中具有不同的含义)。
只需像
一样调用您的脚本python -u script.py
您可以将选项放在script.py
本身:
#!/usr/bin/python -u
# -*- coding: UTF-8 -*-
import os
...
希望它能起作用: - )