Just to illuminate the need for this change.  At import time `sys.stdout` is one thing (probably the "real" stdout of the process), but when running inside of `doctest`, `sys.stdout` is changed to something that collects output so it can be tested against a known value.  This allows us to always use whatever the "current" `sys.stdout` is.