Write text to stdout (and a file) and optionally flush.
(self, text: Union[str, bytes])
| 79 | self.close() |
| 80 | |
| 81 | def write(self, text: Union[str, bytes]) -> None: |
| 82 | """Write text to stdout (and a file) and optionally flush.""" |
| 83 | if isinstance(text, bytes): |
| 84 | text = text.decode() |
| 85 | if len(text) == 0: # workaround for a bug in VSCode debugger: sys.stdout.write(''); sys.stdout.flush() => crash |
| 86 | return |
| 87 | |
| 88 | if self.file is not None: |
| 89 | self.file.write(text) |
| 90 | |
| 91 | self.stdout.write(text) |
| 92 | |
| 93 | if self.should_flush: |
| 94 | self.flush() |
| 95 | |
| 96 | def flush(self) -> None: |
| 97 | """Flush written text to both stdout and a file, if open.""" |
no test coverage detected