Understand Python -u Command – Python Tutorial

By | August 9, 2021

In this tutorial, we will introduce python -u command for python beginners.

What is python -u command?

You can run python -h to understand -u argument in python.

python -h

Run this command, we can get this result.

-u     : force the binary I/O layers of stdout and stderr to be unbuffered;
         stdin is always buffered; text I/O layer will be line-buffered;
         also PYTHONUNBUFFERED=x

It means that python will display information on screen without buffering string.

Understand Python -u Command - Python Tutorial

In python, if we use print() function to display text, stdout will save the text in a buffer, then display it on the screen. However, if you use python -u, print() will make stdout (our screen) display string text directly.

Leave a Reply

Your email address will not be published. Required fields are marked *