code: def stdout_redirector():
      
      old_stdout = sys.stdout
      sys.stdout = Stream()
      try:
          yield sys.stdout
      finally:
          sys.stdout.close()
          sys.stdout = old_stdout
docs: Simplify redirect of stdout.
  
      Taken from here: https://eli.thegreenplace.net/2015/redirecting-all-kinds-of-stdout-in-python/