Paging output from print statement

后端 未结 3 1969
隐瞒了意图╮
隐瞒了意图╮ 2021-01-04 02:52

I\'m essentially trying to achieve this:

>>>print \"SOME_VERY_LONG_TEXT\" | more

Of course, it doesn\'t work in Python 2.7(IDLE).

3条回答
  •  醉梦人生
    2021-01-04 03:23

    Although a bit late, the following worked for me:

    def less(data):
        process = Popen(["less"], stdin=PIPE)
    
        try:
            process.stdin.write(data)
            process.communicate()
        except IOError as e:
            pass
    

提交回复
热议问题