Skip to main content
 首页 » 编程设计

python之帮助 Python while 循环行为

2025年05月04日9落叶无声

我有一个脚本,它使用一个简单的 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))