Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eweka.nl!lightspeed.eweka.nl!69.16.177.246.MISMATCH!cyclone03.ams2.highwinds-media.com!news.highwinds-media.com!voer-me.highwinds-media.com!npeersf03.am4!fx36.am4.POSTED!not-for-mail From: Alister Subject: Re: Limit Lines of Output Newsgroups: comp.lang.python References: <0cb638ec-a4bd-4a45-b98c-a7c76996bab7@googlegroups.com> <842bc651-0bed-45df-9a29-2049279f4434@googlegroups.com> User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508 git://git.gnome.org/pan2) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Lines: 43 Message-ID: NNTP-Posting-Host: 82.18.78.222 X-Complaints-To: http://netreport.virginmedia.com X-Trace: 1372246898 82.18.78.222 (Wed, 26 Jun 2013 11:41:38 UTC) NNTP-Posting-Date: Wed, 26 Jun 2013 11:41:38 UTC Organization: virginmedia.com Date: Wed, 26 Jun 2013 11:41:38 GMT X-Received-Bytes: 2204 Xref: csiph.com comp.lang.python:49249 On Tue, 25 Jun 2013 14:39:30 -0600, Ian Kelly wrote: > On Tue, Jun 25, 2013 at 2:31 PM, Joshua Landau > wrote: >> On 25 June 2013 21:22, Bryan Britten 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