Python presents non-GUI text input and output channels to your programs as file objects, so you can use the methods of file objects (covered in Section 10.3 earlier in this chapter) to manipulate these channels.
sys module, covered
in Chapter 8, has attributes
stderr, file objects
to which you can write. Unless you are using some sort of shell
redirection, these streams connect to the terminal in which your
script is running. Nowadays, actual terminals are rare: the terminal
is generally a screen window that supports text input/output (e.g.,
an MS-DOS Prompt console on Windows or an
window on Unix).
The distinction between
sys.stderr is a matter of convention.
sys.stdout, known as your
script’s standard output, is where your program
sys.stderr, known as your
script’s standard error, is where error messages go.
Separating program results from error messages helps you use shell
redirection effectively. Python respects this convention, using
sys.stderr for error and warning
Programs that output results to
standard output often need to write to
The normal destination of
stdout attribute of the
sys module. ...