Marco Islas

Print pretty progress with python

Sometimes we create a script that may take a long time, one way to know how is it going is to print something to barely know what's going on with the script, sometimes we need to know the progress of the script, particularly in a long long iteration.. To print something nice and don't bloat the shell with stuff we can just write to stdout or stderr and return the line without asking for a new line.

 import sys
 
for i in xrange(10000):
     sys.stdout.write("going on item %5d from 10000\r"%(i+1,))
sys.stdourt.write("\n")
 
 
You can easily customize it to have a percentage or something, even a progress bar is possible.
blog comments powered by Disqus