Python:模拟进度条

import time


def progress(percent):
    if percent > 1:
        percent = 1
    res = int(50 * percent) * '#'print("\r[%-50s] %d%%" % (res, int(100 * percent)), end='')


recv_size = 0
total_size = 102400
while recv_size < total_size:
    # 下载了1024字节的数据
    time.sleep(0.3)
    recv_size += 1024
    # 打印进度条
    percent = recv_size / total_size  # 1024/333333
    progress(percent)
posted @ 2020-06-04 21:29  予之路  阅读(191)  评论(0编辑  收藏  举报