I have a python script which receives values in real-time. My script prints the values as they are received and currently, each update is printed to the screen and the outpu
In python 2.7, the print function will not allow an end
parameter, and print 'Update %d\r'
will also print a newline character.
Here is the same example @elethan gave for python2.7. Note it uses the sys.stdout
output stream:
import sys
import time
output_stream = sys.stdout
for i in xrange(10):
output_stream.write('Update %s\r' % i)
output_stream.flush()
time.sleep(5)
# Optionally add a newline if you want to keep the last update.
output_stream.write('\n')