Set sys.stdout line buffering from environment

Python3 stdout is able to operate in line buffering mode which means flush() is implied when a call to write contains a newline character or a carriage return. There are some recipe to set in code/script, see the following:

sys.stdout.reconfigure(line_buffering=True)
sys.stdout = open(sys.stdout.fileno(), "w", buffering=1)

Is it possible to set it in the Windows/Linux environment variables like PYTHONUNBUFFERED=1 can do the unbuffered mode?

1 Like