python - 带有里程碑的 Python 加载栏
问题描述
我试图用可视化制作一个地下控制程序(当然是为了好玩;D)。我知道有许多不同的加载栏库,但是如果您知道我的意思,我找不到任何具有里程碑意义的东西。我在 Windows 上使用 Python 3。我会感谢任何帮助
解决方案
使用 sys 可以实现带有里程碑的加载栏:
def updt(total, progress):
barLength, status = 25, ""
progress = float(progress) / float(total)
if progress >= 1.:
progress, status = 1, "\r\n"
block = int(round(barLength * progress))
text = "\r[{}] {:.0f}% {}".format(
"#" * block + "-" * (barLength - block), round(progress * 100, 0),
status)
sys.stdout.write(text)
sys.stdout.flush()
runs = 250
for run_num in range(runs):
time.sleep(.1)
updt(runs, run_num + 1)
time.sleep(1)
推荐阅读
- mysql - 带有左连接的 Mysql 查询 - NULL 记录被隐式类型转换
- iframe - 试图弄清楚为什么谷歌分析报告的用户比我们自己的堆栈多
- python - 未使用 .xs() 和 .get_level_values() 在切片上设置值
- c# - Unity3D - 我无法制作帐户创建系统
- jakarta-ee - 同一服务器上独立战争项目之间的通信
- excel - 将共享 Outlook 文件夹的内容导出到 Excel
- c++ - 将 74 位整数转换为基数 31
- javascript - '?' 是什么?在 return 语句中执行
- php - PHP - Mysql - 显示数据
- python - @classmethod 用于构造函数重载