Page through text by invoking a program on a temporary file.
(text: str, cmd: str, title: str = '')
| 163 | |
| 164 | |
| 165 | def tempfile_pager(text: str, cmd: str, title: str = '') -> None: |
| 166 | """Page through text by invoking a program on a temporary file.""" |
| 167 | import tempfile |
| 168 | with tempfile.TemporaryDirectory() as tempdir: |
| 169 | filename = os.path.join(tempdir, 'pydoc.out') |
| 170 | with open(filename, 'w', errors='backslashreplace', |
| 171 | encoding=os.device_encoding(0) if |
| 172 | sys.platform == 'win32' else None |
| 173 | ) as file: |
| 174 | file.write(text) |
| 175 | os.system(cmd + ' "' + filename + '"') |