我需要在控制台中创建简单的进度。像:Python控制台进度
Progress: [######] 30% out of 432 combinations
Last 10 tried:
12.12.2013 - this1
12.12.2013 - this2
...
12.12.2013 - this10
很简单。我发现了一种丑陋的方式:每次都执行clr()并打印(用于进度)。 但我不明白,我怎样才能用不同的数据打印10个字符串。 10次打印很难看,数据一直在变化。有没有办法让一些漂亮的日志进入控制台?对不起我的英语不好。
我的示例代码:
import os
import time
def cls():
os.system(['clear', 'cls'][os.name == 'nt'])
def progress(i, l=None):
total = 400
a = 100-i*100/total
cls()
print "Progress: [%-33s] %d%% out of %d combinations" % ("#"*(a/3), a, total)
print "Last 10 tried:"
for j in l:
print j
time.sleep(0.3)
i = 400
l = []
while i > 0:
l.append("%s - %s" % ('11.21.2013', i))
if len(l) >= 10:
progress(i, l)
l = []
i -= 1
也就是说ehat我需要&但我认为这可以被优化。有人可以帮忙吗?
可能重复的[控制台中的文本进度条](http://stackoverflow.com/questions/3173320/text-progress-bar-in-the-console) – poke 2013-04-08 12:46:53
不,我读那个线程。它只有1线的进展。我需要10 – user2257564 2013-04-08 12:48:27
任何人都可以帮助我吗? – user2257564 2013-04-08 16:42:27