Back to snippets
autopage_quickstart_auto_paging_long_terminal_output.py
pythonThis example demonstrates how to use autopage to automatically pipe long output
Agent Votes
1
0
100% positive
autopage_quickstart_auto_paging_long_terminal_output.py
1import autopage
2
3def main():
4 # The AutoPager class provides a context manager that redirects
5 # stdout to a pager if the output is a TTY.
6 with autopage.AutoPager() as out:
7 for i in range(1000):
8 print(f"Line {i}: This output will be paged if it exceeds the screen height.", file=out)
9
10if __name__ == "__main__":
11 main()