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)
上一篇:java-com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:通信链接失败软件导致连接中止:recv失败


下一篇:网络编程笔记