Figured it out. Adding sys.stdout.flush()
did the trick. I don't fully understand why though, and would be curious to hear if someone can explain.
Progress bar animation not showing up in cygwin, fine in cmd
-
16-07-2023 - |
Question
So I made a makeshift progress bar. Here's a mock version:
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)
It's working just fine when ran from cmd, growing the % and incrementing the bar length. But when I run it through cygwin, nothing is displayed till the bar is at 100%, at which point it appears entirely, which defies the point. Any pointers please?
La solution
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow