Last active
November 20, 2021 12:58
-
-
Save marvintensuan/11ebe670187943f277017e5a7a0e0bb4 to your computer and use it in GitHub Desktop.
Script to show print buffer in Python's print function.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'''This scripts aims to demonstrate the behavior of the `flush` parameter | |
in Python's `print` function. The for-loop below should produce | |
the following output: | |
0123456789 | |
You may modify `END` to change this. | |
Set `IS_BUFFERED` to True to change the manner in which `i` is printed. | |
Lastly, you may experiment with running this script with -u flag. | |
`python -u buffer.py` | |
You may also experiment with manually setting the environment variable | |
PYTHONUNBUFFERED either via command line or via os.environ.''' | |
from time import sleep | |
IS_BUFFERED = False | |
END = "" | |
# import os | |
# os.environ['PYTHONUNBUFFERED'] = "" | |
# print(f"{os.getenv('PYTHONUNBUFFERED') = }") | |
for i in range(10): | |
print(i, end=END, flush=IS_BUFFERED) | |
sleep(0.5) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from rich import print | |
print("[white on red] Hello [/] [green]World!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment