【问题标题】:Python progress bar with a fixed size in a variable withtout print变量中具有固定大小的Python进度条,没有打印
【发布时间】:2019-12-09 20:11:03
【问题描述】:

从此python3代码:

#!/usr/bin/env python3

from progress.bar import Bar

bar = Bar("Percent of this year : ", max=100)
for i in range(int(50)):
    bar.next()
bar.finish()

我在控制台中打印了这个输出:

Percent of this year :  |################                | 50/100

输出正是我需要的,但我不想将它用作控制台中的打印输出。

我需要将它保存在要写入文件的变量中。

我想要这个结果:

print(myvar)
Percent of this year :  |################                | 50/100

【问题讨论】:

  • 为什么需要将其存储在变量中?您是否考虑过将输出重定向到“python 文件名> output.log”之类的日志文件。 ?

标签: python python-3.x progress-bar


【解决方案1】:

我找到了解决办法:

percent = 70
barre = (
    "["
    + "#" * int((50 / 100) * percent)
    + "-" * int((50 / 100) * (100 - percent))
    + "]"
)
BarrEarth = "Percent of this year : " + (barre) + str("\n")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多