code: def get_stream_handle(stream=sys.stdout):
      
      handle = stream
      if os.name == "nt":
          from ctypes import windll
  
          handle_id = WIN_STDOUT_HANDLE_ID
          handle = windll.kernel32.GetStdHandle(handle_id)
      return handle
docs: Get the OS appropriate handle for the corresponding output stream.
  
      :param str stream: The the stream to get the handle for
      :return: A handle to the appropriate stream, either a ctypes buffer
               or **sys.stdout** or **sys.stderr**.