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).

Answer from CesarB on Stack Overflow
🌐
Real Python
realpython.com › python-flush-print-output
How to Flush the Output of the Python Print Function – Real Python
January 25, 2025 - Because you’re writing to the terminal, which represents an interactive environment, print() executes line-buffered. Therefore, it flushes the data buffer at the end of each call, and each number gets sent to the terminal with its own system call.
🌐
Codemia
codemia.io › knowledge-hub › path › how_can_i_flush_the_output_of_the_print_function_1
How can I flush the output of the print function?
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises
🌐
Medium
medium.com › @ryan_forrester_ › python-print-flush-complete-guide-b10ab1512390
Python Print Flush: Complete Guide | by ryan | Medium
October 30, 2024 - This script shows: 1. Current progress updates in real-time 2. Uses `\r` to update the same line 3. Left-aligns filenames with `:❤0` for clean formatting 4. Flushes output for immediate updates ... import time import sys def spinning_cursor(): """Create a spinning cursor animation""" cursors = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'] for _ in range(50): # Spin 50 times for cursor in cursors: # Print cursor and go back one character sys.stdout.write(cursor) sys.stdout.flush() time.sleep(0.1) sys.stdout.write('\b') # Run the animation print("Loading ", end='') spinning_cursor() print(" Done!")
🌐
GitHub
github.com › micropython › micropython › issues › 7950
`flush` keyword argument for `print()`? · Issue #7950 · micropython/micropython
October 29, 2021 - CPython 3.3+ supports a flush keyword argument. https://docs.python.org/3/library/functions.html#print $ micropython MicroPython 4fe0332-dirty on 2021-10-27; linux version Use Ctrl-D to exit, Ctrl-E for paste mode >>> print(5, flush=True...
Author   will-ca
🌐
Stack Abuse
stackabuse.com › bytes › flush-the-output-of-the-print-function-in-python
Flush the Output of the print() Function in Python
August 29, 2023 - By default, flush is set to False, which means the buffer is not flushed after each call to print. If you set flush to True, Python will flush the output buffer after each print call.
Find elsewhere
🌐
Google Groups
groups.google.com › g › sage-devel › c › aGX7GlvkAWg › m › dMGG4T_GDwAJ
Python 3 and flushing output from external libraries
Ideally, the upstream library should properly flush when producing output. They should use fflush (in C) or std::endl or std::flush (in C++). I guess that Sage could also do the flushing whenever we return from a library API call. > I'm also curious about what's causing the problem.
🌐
DEV Community
dev.to › marvintensuan › pythons-print-and-the-flush-parameter-3d7k
Python's print and the flush parameter. - DEV Community
January 15, 2022 - These two lines show rich.print overriding Python's built-in print function. One thing that caught my attention is rich.print's docstring, especially this line: flush (bool, optional): Has no effect as Rich always flushes output.
🌐
Plain English
python.plainenglish.io › understanding-pythons-print-arguments-flush-sep-end-file-ee54850ac6a1
Understanding Python’s print() Arguments — flush, sep, end, file | by Ganesh Bajaj | Python in Plain English
February 20, 2025 - Understanding Python’s print() Arguments — flush, sep, end, file The print() function in python is the most standard and commonly used functions to write/print in the console. print() has several …
🌐
W3Schools
w3schools.com › python › ref_func_print.asp
Python print() Function
The message can be a string, or any other object, the object will be converted into a string before written to the screen. print(object(s), sep=separator, end=end, file=file, flush=flush) Print more than one object: print("Hello", "how are you?") ...
🌐
Python.org
discuss.python.org › python help
How to flush Python logger - Python Help - Discussions on Python.org
August 31, 2024 - Hello, I need help from an expert in figuring out how to flush my logger. I see data failing to print to my stream handler “console” (self.console) and if I access the logging module and have it print more stuff with my…
🌐
GeeksforGeeks
geeksforgeeks.org › python › file-flush-method-in-python
File flush() method in Python - GeeksforGeeks
July 12, 2025 - Example 2: This example simulates item processing and uses flush=True with print() to instantly display each update in the console without buffering delays.
🌐
ZetCode
zetcode.com › python › flush
Python flush Function - Complete Guide
March 26, 2025 - The flush method is also available on sys.stdout, which is useful when you need to ensure output appears immediately in consoles or pipes. ... import sys import time print("This appears immediately", flush=True) print("This might be buffered") for i in range(5): print(f"Progress: {i+1}/5", end='\r') time.sleep(1) print("\nDone", flush=True)
🌐
Python Reference
python-reference.readthedocs.io › en › latest › docs › file › flush.html
flush — Python Reference (The Right Way) 0.1 documentation
>>> fw = open(r'C:\test.txt', "w") >>> fw.write('foobar') >>> fr = open(r'C:\test.txt') >>> fr.readlines() # even though we just wrote a line to the fr file it appears empty until close() method is called [] >>> fw.flush() # flushing forces the buffer content into the file without closing it >>> fr.readlines() ['foobar']
🌐
Real Python
realpython.com › videos › sep-end-and-flush
sep, end, and flush (Video) – Real Python
05:10 This is probably not the effect that you’re looking for. The reason for this is print() actually puts the strings into a buffer. When it encounters the \n, it flushes that buffer and sends it to the screen.
Published   May 5, 2020
🌐
W3docs
w3docs.com › python
How can I flush the output of the print function?
Python · How can I flush the output of the print function? To flush the output of the print function, you can use the flush parameter of the print function. By default, the flush parameter is set to False, which means that the output is buffered ...
🌐
TestDriven.io
testdriven.io › tips › bbb44570-66d1-4ff5-af6a-5e3a2dc5e02a
Tips and Tricks - How to flush output of print in Python? | TestDriven.io
Python tip: You can set flush=True for the print() function to avoid buffering the output data and forcibly flush it: print("I'm awesome", flush=True) View All Tips · Feedback · × ·