Percent indication in place

Andrew M. Kuchling akuchlin at cnri.reston.va.us
Thu May 6 14:53:44 EDT 1999


colmconn at my-dejanews.com writes:
>How can I display a percentage-done indication that updates itself in place,
>or show a "twirling baton" progress indicator?

	 On a Unix terminal (and probably on an MS-DOS console), you
can just print chr(8) to backspace, so a twirling display would look
something like this:

import time, sys
sys.stdout.write(' ')

for i in '|/-\|':
    sys.stdout.write( chr(8)+i ) ; sys.stdout.flush() ; time.sleep(1)
print

You have to flush standard output after each character so it gets
immediately printed; otherwise they'll be buffered up, and the user
won't see them.

-- 
A.M. Kuchling			http://starship.python.net/crew/amk/
You didn't join the rebellion, not because you felt I was wrong, but because
you were too damned scared. What would you have done, had I won? Told me that
you'd always supported me ideologically? That you were secretly cheering me on
the whole time?
    -- Lucifer berates Remiel, in SANDMAN #60: "The Kindly Ones:4"





More information about the Python-list mailing list