How to better control print and stdout?

Jeff Epler jepler at
Sat Mar 15 00:24:39 CET 2003

You need to call the flush method on sys.stdout, or set it unbuffered.
In my example, I also use sys.stdout.write instead of print, and \r to move
the cursor back to the beginning of the line.  but sys.stdout.flush() is
the key.


import time, sys
def spinner(rotations, interval):
    for i in range(rotations):
        sys.stdout.write("|/-\\"[i % 4] + "\r"); sys.stdout.flush()
    sys.stdout.write("\b\b"); sys.stdout.flush()

More information about the Python-list mailing list