What you should have when you play a slightly longer script and leave it
An example of turning something n times with a for statement
import sys
import time
def something():
time.sleep(t_sleep)
pass
def update_progbar(progress):
prog_length = int(bar_length * progress)
return ('[[' + '-' * prog_length +
('>' if prog_length < bar_length else '') +
'*' * (bar_length - prog_length) +
']] %.1f%%' % (progress * 100.))
n = 123
t_sleep = 0.05
bar_length = 30
t0 = time.time()
t1 = t0
print '\n'
for i in range(n):
something()
t2 = time.time()
progress = i/float(n)
t_remain = (t2 - t1) * (n - i)
sys.stderr.write('\r\033[K' + update_progbar(progress)+
" Remaining: %.1f sec"%t_remain)
sys.stderr.flush()
t1 = time.time()
sys.stderr.write('\r\033[K' + update_progbar(1.0))
print '\n'
print 'Total: %.1f sec'%(t1 - t0), time.ctime()
print '\n'
reference: http://www.yunabe.jp/docs/terminal_progress_bar.html
However, even if you don't do this, there seems to be a module called tqdm these days ... https://pypi.python.org/pypi/tqdm http://postd.cc/my-top-5-new-python-modules-of-2015/
Recommended Posts