Python全栈开发:进度条

import sys
import time
for i in range(31):
    # 清空打印内容
    sys.stdout.write("\r")
    # 控制输出样式
    sys.stdout.write("%d%% | %s" % (int(i/30*100), int(i/30*100)*"*"))
    # 刷新缓存
    sys.stdout.flush()
    # 控制打印速度
    time.sleep(0.3)

  

#!/usr/bin/env python
# -*- coding;utf-8 -*-
import sys
import time


def jindu(fenzi, fenmu=100):
    rate = float(fenzi) / float(fenmu)
    rate_num = int(rate * 100)
    str_jindu = "*" * int(rate_num / 2)
    shuchu = "\r%s %d%%" % (str_jindu, rate_num)
    sys.stdout.write(shuchu)
    sys.stdout.flush()

for i in range(1, 101):
    time.sleep(0.1)
    jindu(i)

  

posted @ 2017-03-02 16:58  倪兴国  阅读(197)  评论(0编辑  收藏  举报