Python — How do you view output that doesn't fit the screen?

前端 未结 9 1733
挽巷
挽巷 2021-02-05 10:27

I should say I\'m looking for a solution to the problem of viewing output that does not fit on your screen. For example, range(100) will show the last 30ish lin

9条回答
  •  长发绾君心
    2021-02-05 10:52

    It's easy to write your own:

    def less(s, line_count = 5):
        lines = []
        for i, line in enumerate(s.split('\n'), 1):
            lines.append(line)
            if (i % line_count) == 0:
                yield '\n'.join(lines)
                lines = []
    
        if lines:
            yield '\n'.join(lines)
    

提交回复
热议问题