import sys
import time
def progress(percent,width=50):
if percent >= 1:
percent=1
show_str=('%%-%ds' %width) %(int(widthpercent)'█')
print('
%s %d%%' %(show_str,int(100*percent)),file=sys.stdout,flush=True,end='')
=应用==
data_size=1025
recv_size=0
while recv_size < data_size:
time.sleep(0.1) #模拟数据的传输延迟
recv_size+=4 #每次收
percent=recv_size/data_size #接收的比例
progress(percent,width=70) #进度条的宽度70