python - Stdout and flush? It's appending and not flushing -
what i'm trying have 'progress text' on bottom of script i've creating. if loop list [1,2,3,4,5] , print i, prints 1,2,3,4, , 5 on separate lines. how if want print 1 out screen, sleep 5 seconds, clear out , print 2?
i've tried using stdout.write("text"), sleep, flush, stdout.write("aetlkjetjer"), sleep, , adds on "text" statement instead of flushing output.
am misunderstanding way stdout.flush works? isn't supposed flush/erase output of previous print?
all .flush()
flush out buffer. want write backspace(\b
) stdout
.
import time, sys in [1,2,3,4,5]: sys.stdout.write(str(i)) sys.stdout.flush() #flush buffer because python buffers stdout time.sleep(5) sys.stdout.write("\b") #literally "write backspace". sys.stdout.flush()
it gets more complicated if want count numbers more 1 digit.
Comments
Post a Comment