August 6, 2008
[Daniel] Command-Line Status Updates
"""
A simple but useful command-line trick.
To output a status update that stays on a single line, end your line with
\r instead of \n. This will cause the next line to print over the top of the
current one. Be sure to output an extra blank newline (\n) once your loop is
complete to retain the information (like the last record processed).
Works on Linux & Mac as it should, generates a ton of (correct) output on
Windows. Works in all programming languages I've tried (PHP, Perl, Ruby, etc.),
not just Python.
"""
for i in xrange(0, 100):
# Processing happens here.
print "Percent complete - %s%%\r" % i,
print
print "Complete!"
Permalink
|
Comments (0)

