The problem of the function of sys.stdout.flush ()

the information found is said to be real-time output display, and there is a sample code

import time
import sys

for i in range(5):
    print(i)
    sys.stdout.flush()
    time.sleep(1)

but I try to annotate him and there is no difference between annotating him and not commenting it. It"s a number per second. I use python3

.
May.08,2021

https://stackoverflow.com/que.

the point is that your situation is normal and this code is useful.
this line of code is mainly to prevent the output to the terminal from being cached by python, but through the environment variable,-u starts python and the running system, it can affect the cache or not. This code ensures that it can output 1 number per second in all places, and after removal, it will be cached in some places.
and your computer just doesn't use caching.
seems to be very little of windows (won't?) Cached occurs.


if you are using PYTHON3, your code should be changed to print (iJournal enduring codes'), then there will be a change

Menu