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)