Limit Lines of Output

Alister alister.ware at ntlworld.com
Wed Jun 26 07:41:38 EDT 2013


On Tue, 25 Jun 2013 14:39:30 -0600, Ian Kelly wrote:

> 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

this would be my approach
it leaves it to the user to decide what to do with the output (they may 
even decide to write it to a file themselves)

and obeys to very good principles

1) Do not re-invent the wheel.
2) do only 1 job but do it well. 




-- 
"Every morning, I get up and look through the 'Forbes' list of the
richest people in America.  If I'm not there, I go to work"
		-- Robert Orben



More information about the Python-list mailing list