How to write python script with man-page like out-

2019-09-14 15:50发布

问题:

This question already has an answer here:

  • Paging output from python 4 answers

I wonder how to write a script with stdout like command-line like 'more', 'less', 'man' which it is seems they show their result in another layer of bash. how can I write a program with such output in python?

回答1:

You can use pydoc.pager for that. It's in the standard library.

from pydoc import pager
pager('hello world\n' * 100)