def METHOD_NAME(self, console: "Console") -> Iterator:
    stdout_file = None
    if self.output_file:
        stdout_file = open(self.output_file, "w")
        METHOD_NAME = stdout_file
    else:
        METHOD_NAME = console.stdout  # type: ignore[assignment]
    try:
        yield METHOD_NAME
    finally:
        METHOD_NAME.flush()
        if stdout_file:
            stdout_file.close()