Context manager to temporarily set the output stream during argparse operations. This is helpful for directing output for functions like `parse_args()`, which default to `sys.stdout` and lack a `file` argument. :param file: the file stream to use for output
(self, file: IO[str] | None)
| 569 | |
| 570 | @contextlib.contextmanager |
| 571 | def output_to(self, file: IO[str] | None) -> Iterator[None]: |
| 572 | """Context manager to temporarily set the output stream during argparse operations. |
| 573 | |
| 574 | This is helpful for directing output for functions like `parse_args()`, which |
| 575 | default to `sys.stdout` and lack a `file` argument. |
| 576 | |
| 577 | :param file: the file stream to use for output |
| 578 | """ |
| 579 | previous = self._thread_locals.current_output_file |
| 580 | self._thread_locals.current_output_file = file |
| 581 | try: |
| 582 | yield |
| 583 | finally: |
| 584 | self._thread_locals.current_output_file = previous |
| 585 | |
| 586 | def __init__( |
| 587 | self, |
no outgoing calls