import time def bar(num=1, total=100): rate = float(num) / float(total) rate_num = int(rate * 100) temp = ‘\r%d %%‘ % (rate_num, ) sys.stdout.write(temp) sys.stdout.flush() def test(): i = 0 while True: i += 1 time.sleep(0.1) bar(i, 100) if i == 100: break if __name__ == ‘__main__‘: test()
原文:https://www.cnblogs.com/dongmengze/p/9618464.html