Writing to the standard error stream

There are two commonly used Unix output streams, standard output and standard error. Often we want our code to produce standard output that can be redirected to a file. If the code also generates error messages, we would want those messages to appear on our screen immediately and not have them also be redirected to the file where we might miss them. In that case, we should write our error messages to the standard error stream. Its file object is called sys.stderr. Here is how:

import sys
sys.stderr.write("There are no real roots\n")