进度百分比

  •  输出进度百分比
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()

 

posted @ 2018-09-10 12:16  运维00001  阅读(171)  评论(0编辑  收藏  举报