Primary
sys.stdout ⚬|Documentation|1st|20251021175842-00-⌔
sys — System-specific parameters and functions — Python 3 documentation#sys.stdout
sys.stdout
sys.stderrFile objects used by the interpreter for standard input, output and errors:
stdinis used for all interactive input (including calls toinput());stdoutis used for the output ofprint()and expression statements and for the prompts ofinput();- The interpreter’s own prompts and its error messages go to
stderr.These streams are regular text files like those returned by the
open()function. Their parameters are chosen as follows:
- The encoding and error handling are is initialized from
PyConfig.stdio_encodingandPyConfig.stdio_errors. On Windows, UTF-8 is used for the console device. Non-character devices such as disk files and pipes use the system locale encoding (i.e. the ANSI codepage). Non-console character devices such as NUL (i.e. whereisatty()returnsTrue) use the value of the console input and output codepages at startup, respectively for stdin and stdout/stderr. This defaults to the system locale encoding if the process is not initially attached to a console. The special behaviour of the console can be overridden by setting the environment variable PYTHONLEGACYWINDOWSSTDIO before starting Python. In that case, the console codepages are used as for any other character device. Under all platforms, you can override the character encoding by setting thePYTHONIOENCODINGenvironment variable before starting Python or by using the new-Xutf8command line option andPYTHONUTF8environment variable. However, for the Windows console, this only applies whenPYTHONLEGACYWINDOWSSTDIOis also set.- When interactive, the
stdoutstream is line-buffered. Otherwise, it is block-buffered like regular text files. Thestderrstream is line-buffered in both cases. You can make both streams unbuffered by passing the-ucommand-line option or setting thePYTHONUNBUFFEREDenvironment variable.Changed in version 3.9: Non-interactive
stderris now line-buffered instead of fully buffered.Note: To write or read binary data from/to the standard streams, use the underlying binary
bufferobject. For example, to write bytes tostdout, usesys.stdout.buffer.write(b'abc').However, if you are writing a library (and do not control in which context its code will be executed), be aware that the standard streams may be replaced with file-like objects like
io.StringIOwhich do not support thebufferattribute.Printed 2026-06-28.
(echo:: @ ᯤ)
Link to original
Secondary
• • •