-1

I need to create simple progress in console. Like:

Progress: [######] 30% out of 432 combinations
Last 10 tried:
12.12.2013 - this1
12.12.2013 - this2
...
12.12.2013 - this10

Pretty simple. I found an ugly way: do clr() each time and do print (for progression). But I can't understand, how can I print 10 strings down withdifferent data. 10 time print is ugly, data alway changes. Is there a way to some nice log into console? sorry for my english.

My sample code:

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

That is ehat I need& But I think it can be optimized. Could someone help?

Charles
  • 50,943
  • 13
  • 104
  • 142

1 Answers1

0

I do it as follows

print (current_line * 100 // total_lines, "%", end = '\r')

Don't forget, that too many outputs to console will slow down your loops.

poke
  • 369,085
  • 72
  • 557
  • 602