python - 帮助 Python while 循环行为

标签 python while-loop

我有一个脚本,它使用一个简单的 while 循环来显示进度条,但它似乎没有像我预期的那样工作:

count = 1
maxrecords = len(international)
p = ProgressBar("Blue")
t = time
while count < maxrecords:
    print 'Processing %d of %d' % (count, maxrecords)
    percent = float(count) / float(maxrecords) * 100
    p.render(int(percent))
    t.sleep(0.5)
    count += 1

它似乎在“p.render...”处循环并且不会返回到“打印‘Processing %d of %d...’”。

更新:我很抱歉。 ProgressBar.render() 似乎在呈现进度条时删除了“print 'Processing ...”的输出。进度条来自http://nadiana.com/animated-terminal-progress-bar-in-python

最佳答案

我看到您在我的网站上使用 ProgressBar 实现。如果你想打印一条消息,你可以在 render 中使用 message 参数

p.render(percent, message='Processing %d of %d' % (count, maxrecords))

关于python - 帮助 Python while 循环行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1312421/

相关文章:

java - while '(' 后的空语句预期错误

python - AttributeError :'module' 对象没有属性 'call' :Python

Python:使用 while 或 for 循环遍历列表

如果符合条件,则替换字符串的最后一个字符

matlab - while 循环内有 for 循环

c - while 循环中的 scanf 函数

python - 如何在 lambda 中为 tkinter 按钮分配变量

python - 在 python 中使用 % 格式时换行

python - OpenGL 中的子像素渲染 - 精度问题

python - PyQt4->PyQt5 翻译