python-实现文本进度条

单行刷新统计时间类型文本进度条

import time
scale=50 #尽量不要超过50 超过屏幕宽度会自动执行换行
print("执行开始".center(scale//2,"-"))
start=time.perf_counter()
for i in range(scale+1):
	a="*"*i
	b="."*(scale-i)
	c=(i/scale)*100
	dur=time.perf_counter()-start
	print("\r{:<3.0f}%[{}->{}] time:{:.2f}".format(c,a,b,dur),end="")
	#\r将光标移动到前面
	#{:^3.0f} 左对齐 保留3位整数位 保留0位小数位
	time.sleep(0.1)
print("\n")
print("执行结束".center(scale//2,"-"))

进度条速度算法
请根据需要自行添加进去
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_44647926/article/details/89499842