进度条的制作-python

import time,sys


def view_bar(num, total):
    rate = float(num) / float(total)
    rate_num = int(rate * 100)
    r = '\r%s %d%%'%('>'*rate_num,rate_num)
    sys.stdout.write(r)
    sys.stdout.flush()


if __name__ == '__main__':
    for i in range(0, 100):
        time.sleep(0.1)
        view_bar(i, 100)
posted @ 2018-05-24 10:20  nkwy2012  阅读(348)  评论(0编辑  收藏  举报