python - 如何在Python中显示百分比和进度条?

标签 python progress-bar f-string format-string

在 python 中我可以显示进度条:

import time 
print("0%\u2502{:>21s}0%".format("\u2502"), end='')
print("\b"*23,end='')
for _ in range(20):
    print("\u2588", end='')
    time.sleep(.05)

我还想显示百分比。我怎样才能做到这一点?

最佳答案

这就是我完成这项任务的方式

import time
import sys

bar = ''
for i in range(100):
    bar += "\u2588"
    sys.stdout.write(bar+"\r%d%%" % i)
    sys.stdout.flush()
    time.sleep(0.05)

基本上,bar字符串包含在控制台上打印的进度条。

关于python - 如何在Python中显示百分比和进度条?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69153531/

相关文章:

python - key 错误 : "[' petal length'] not in index"

python - 使用制表 Python 包生成适当的 LaTeX 表

c# - 如何使用服务器端任务的进度更新网页?

python - 如何将列表插入 Python 中的 f 字符串?

regex - 如何使用正则表达式格式化 f 字符串?

python - Pandas根据Excel中的条件更改字体颜色并保存到相同的excel python

python - docker-compose 不在 Python 应用程序中打印标准输出

c# - backgroundWorker 和 progressChanged 不工作

objective-c - Mac 的 UIProgressView 类似控件

python - 为什么 f-strings 在它们引用的变量发生变化时不发生变化?