Limit Lines of Output

Ian Kelly ian.g.kelly at gmail.com
Tue Jun 25 16:39:30 EDT 2013


On Tue, Jun 25, 2013 at 2:31 PM, Joshua Landau
<joshua.landau.ws at gmail.com> wrote:
> On 25 June 2013 21:22, Bryan Britten <britten.bryan at gmail.com> wrote:
>> Ah, I always forget to mention my OS on these forums. I'm running Windows.
>
> Supposedly, Windows has "more"
> [http://superuser.com/questions/426226/less-or-more-in-windows],
>
> For Linux+less; this works:
>
> from subprocess import Popen, PIPE
> less = Popen("less", stdin=PIPE)
> less.stdin.write(b"\n".join("This is line number
> {}".format(i).encode("UTF-8") for i in range(1000)))
> less.wait()


Or simply:

$ python my_script.py | less

It works the same way in Windows:

C:\> python my_script.py | more



More information about the Python-list mailing list