If it's just one print statement you're concerned with then you only need to import the "sys" module and call "sys.stdout.flush()" in order to force the program to show anything that has been printed but is still hidden in the buffer.
import sys print('bla bla bla') sys.stdout.flush()
But most of the time you want this to always happen and not after some particular point in the program. To force Python to always show whatever is printed just add the command line option "-u" when running python.
> python -u myscript.py
You can read more about it here:
https://docs.python.org/3.6/using/cmdline.html#cmdoption-u
No comments:
Post a Comment