Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 进度条动画未在cygwin中显示,在cmd中显示良好_Python_Python 2.7_Progress Bar - Fatal编程技术网

Python 进度条动画未在cygwin中显示,在cmd中显示良好

Python 进度条动画未在cygwin中显示,在cmd中显示良好,python,python-2.7,progress-bar,Python,Python 2.7,Progress Bar,所以我做了一个临时的进度条。这是一个模拟版本: import sys, time def Round(n): return str("{0:.2f}".format(n)) def updateProgressBar(label, percentage): width = 20 done = width * int(percentage)/100 sys.stdout.write('\r' + label + '\t[' + done * '*' + (wid

所以我做了一个临时的进度条。这是一个模拟版本:

import sys, time

def Round(n):
    return str("{0:.2f}".format(n))

def updateProgressBar(label, percentage):
    width = 20
    done = width * int(percentage)/100
    sys.stdout.write('\r' + label + '\t[' + done * '*' + (width-done) * ' ' + ']\t' + Round(percentage) + '%')

n = 23
for i in range(n+1):
    time.sleep(0.25)
    updateProgressBar('Testing', 100*float(i)/n)

从cmd运行时,它工作正常,增加了%并增加了条长度。但当我在cygwin中运行它时,在该条为100%之前,不会显示任何内容,此时它会完全显示出来,这与该点背道而驰。有什么建议吗?

找到了。添加
sys.stdout.flush()
成功了。我不完全明白为什么,我很想知道是否有人能解释