一个简单的解决方案是只
"r"在字符串之前编写而不添加换行符。如果字符串永远不会变短,那就足够了…
sys.stdout.write("rDoing thing %i" % i)sys.stdout.flush()进度条稍微复杂一点……这是我正在使用的东西:
def startProgress(title): global progress_x sys.stdout.write(title + ": [" + "-"*40 + "]" + chr(8)*41) sys.stdout.flush() progress_x = 0def progress(x): global progress_x x = int(x * 40 // 100) sys.stdout.write("#" * (x - progress_x)) sys.stdout.flush() progress_x = xdef endProgress(): sys.stdout.write("#" * (40 - progress_x) + "]n") sys.stdout.flush()你调用
startProgress传递操作的描述,然后
progress(x)在那里
x是个和最后
endProgress()



