I\'m running python version 2.7.3 on MacOSX.
Consider this block of code:
from __future__ import print_function
import time
x = 0
while x < 5:
This is just python buffering stdout. This answer has some more info.
You can flush it like this:
import sys
from __future__ import print_function
import time
x = 0
while x < 5:
print(x, end='')
x += 1
sys.stdout.flush()
time.sleep(1)
Alternatively start python python -u
and it won't be buffered.
Because the output stream is line-buffered - since it's not explicitly being flushed in between print statements, it waits until it sees a newline to flush the output.
You can force flushing via sys.stdout.flush()
.
Alternatively if you run Python with the -u
flag, it will disable line buffering.