Problems with sys.stout.flush()

Joel Ross joelc at
Sat May 23 07:33:00 CEST 2009

Hi all,

I'm using python 2.5 and trying to flush the sys.stout buffer with 
sys.stout.flush(), but doesn't seem to work. Each time a line is printed 
   it appends the one before it I need to clear the output and write a 
new output without appending the previous one. I have tried the -u 
(unbuffered) option for python and a few examples from this site


import sys
from time import sleep

def progress(number, total,  char):

     percentage = float(number*100)/total
     percentage = int(round(percentage))
     percentage = int(100 - percentage)
     if percentage > 0:
         char = char * percentage
         sys.stdout.flush()      #Not working correctly

progress(40, 50, "*")
progress(30, 50, "*")
progress(20, 50, "*")
progress(10, 50, "*")
progress(2, 50, "*")



More information about the Python-list mailing list