Thursday, September 15, 2022

[FIXED] How can I flush the output of the print function?

Issue

How do I force Python's print function to flush the buffered output to the screen?


Solution

In Python 3, print can take an optional flush argument:

print("Hello, World!", flush=True)

In Python 2, after calling print, do:

import sys
sys.stdout.flush()

By default, print prints to sys.stdout (see the documentation for more about file objects).



Answered By - CesarB
Answer Checked By - Timothy Miller (PHPFixing Admin)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.