code: def redirectSTDOUTtoDebugFile():
      
      import sys
      kwargs = {}
      if sys.version_info >= (3,):
          kwargs["encoding"] = "utf8"
      sys.stdout = open(
          os.path.join(
              getDebugDirectory(),
              "{0}.stdout".format(getDebugIdentifier()),
          ),
          "w",
          1, # Buffering by line
          **kwargs
      )
      sys.stderr = open(
          os.path.join(
              getDebugDirectory(),
              "{0}.stderr".format(getDebugIdentifier()),
          ),
          "w",
          1, # Buffering by line
          **kwargs
      )
docs: Redirects the stdout and stderr of the current process to a file.