Re: [Tutor] Scrolling through output in shell
Lie Ryan wrote: As the manpage of "less" explains: 'less - opposite of more' I've always heard it explained that "more" is the original paging program of UNIX, and when a new pager was created (by GNU?) they named it "less" because, as we all know, "less is more"[1]. Simón [1] http://www.phrases.org.uk/meanings/226400.html (for those to whom English is not a primary language, or just anyone who doesn't get the "joke".) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Scrolling through output in shell
Lie Ryan wrote: As the manpage of "less" explains: 'less - opposite of more' I've always heard it explained that "more" is the original paging program of UNIX, and when a new pager was created (by GNU?) they named it "less" because, as we all know, "less is more"[1]. Simón [1] http://www.phrases.org.uk/meanings/226400.html (for those to whom English is not a primary language, or just anyone who doesn't get the "joke".) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Scrolling through output in shell
os.system("cat textfile | less") did the trick, thanks everyone. On Wed, Nov 19, 2008 at 2:34 PM, Lie Ryan <[EMAIL PROTECTED]> wrote: > On Mon, 17 Nov 2008 09:20:55 -0500, Shawn Milochik wrote: > >> On Sun, Nov 16, 2008 at 1:21 PM, Mike Hoy <[EMAIL PROTECTED]> wrote: >>> I'm writing a small program that writes to a text file. I want to be >>> able to view the contents of the text file inside of shell. But the >>> file is too large for a small shell window. Is there a way for the user >>> to 'scroll' through the contents of file that has been read into the >>> program? I noticed that on the man pages that you can do that although >>> I'm sure it's not written in python. Do I need to find a new language >>> to write this in? Maybe use a different language for the output and >>> still use python? Any help appreciated. >>> >>> -- >>> Mike Hoy >>> http://www.mikehoy.net >> >> >> >> As Alan has noted, your request isn't perfectly clear. So, I'm going to >> change your question and answer it. If I picked the wrong question, >> please be more explicit in your next reply. >> >> Question: How can I read a text file from the command line if the file >> is too large to fit on the screen at once? >> >> Answer: more or less >> If you're in Windows, you can use the more command: more file.txt That >> will allow you to scroll up and down. >> >> If you're on pretty much any other OS, you can use more or less. I >> prefer less, because it has more features. You use it the same way you >> use more: less file.txt > > If that explanations mixing up "more" and "less" as names of programs and > more and less for real more and less doesn't confuse you, I think you > must already know what "more" and "less" is. > > "more" and "less" is a pager program, used to provide scroll facility to > a file or a stream. Windows only have "more", many Unix-like OS provide > both "more" and "less". The most striking difference between "more" and > "less" is that "more" is simple forward-only, you can't scroll up, only > down. "less" support both backward and forward navigation. > > As the manpage of "less" explains: 'less - opposite of more' > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > > -- Mike Hoy ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Scrolling through output in shell
"Lie Ryan" <[EMAIL PROTECTED]> wrote both "more" and "less". The most striking difference between "more" and "less" is that "more" is simple forward-only, you can't scroll up, only down. "less" support both backward and forward navigation. On very early Unices that was true but for the last 20 years more has had two direction paging plus searching etc. more also usually supports the v key which takes you into view (which is read-only vi) and some mores even have an e key to take you to the EDITOR. less is like many of the GNU tools an early equivalent to more which grew extra features and some slight inconsistencies. The biggest difference that I find vbetween more and less is that you always have to exit from less whereas more usually exits automatically at the end of file - which is a real pain if you want to go back to the second last page! And for that reason alone I usually use less. (I believe less can also be configured to use the emacs keystrokes rather than the vi keys of more although I've never tried that.) Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Scrolling through output in shell
On Mon, 17 Nov 2008 09:20:55 -0500, Shawn Milochik wrote: > On Sun, Nov 16, 2008 at 1:21 PM, Mike Hoy <[EMAIL PROTECTED]> wrote: >> I'm writing a small program that writes to a text file. I want to be >> able to view the contents of the text file inside of shell. But the >> file is too large for a small shell window. Is there a way for the user >> to 'scroll' through the contents of file that has been read into the >> program? I noticed that on the man pages that you can do that although >> I'm sure it's not written in python. Do I need to find a new language >> to write this in? Maybe use a different language for the output and >> still use python? Any help appreciated. >> >> -- >> Mike Hoy >> http://www.mikehoy.net > > > > As Alan has noted, your request isn't perfectly clear. So, I'm going to > change your question and answer it. If I picked the wrong question, > please be more explicit in your next reply. > > Question: How can I read a text file from the command line if the file > is too large to fit on the screen at once? > > Answer: more or less > If you're in Windows, you can use the more command: more file.txt That > will allow you to scroll up and down. > > If you're on pretty much any other OS, you can use more or less. I > prefer less, because it has more features. You use it the same way you > use more: less file.txt If that explanations mixing up "more" and "less" as names of programs and more and less for real more and less doesn't confuse you, I think you must already know what "more" and "less" is. "more" and "less" is a pager program, used to provide scroll facility to a file or a stream. Windows only have "more", many Unix-like OS provide both "more" and "less". The most striking difference between "more" and "less" is that "more" is simple forward-only, you can't scroll up, only down. "less" support both backward and forward navigation. As the manpage of "less" explains: 'less - opposite of more' ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Scrolling through output in shell
On Monday 17 November 2008, ALAN GAULD wrote: > > I'm writing a program that reads a text file onto the screen. The > > text file is too large to read so I want to be able to scroll > > through it with the arrow key or something like that. I am not > > using GUI. You could also output the text, and give it to 'less' to display it. This is exactly what 'man' does. You start other programs from python with the 'subprocess' module: http://docs.python.org/library/subprocess.html You could also go the classical Unix way and output the text to standard output (just use print). If necessary you could then give the output to 'less'. Your program(s) would be used in the following fashion: my_program --foo -a -b -c --be-cool --read this-file.txt | less Command line options are parsed with the 'optparse' module: http://docs.python.org/library/optparse.html Kind regards, Eike. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Scrolling through output in shell
Ok thanks Alan for looking into it. I'll give it a try. On Mon, Nov 17, 2008 at 12:27 PM, ALAN GAULD <[EMAIL PROTECTED]> wrote: > Forwarding to the group. > Please use Reply All when responding. > > > - Original Message > From: Mike Hoy <[EMAIL PROTECTED]> > To: Alan Gauld <[EMAIL PROTECTED]> > > >> I'm writing a program that reads a text file onto the screen. The text >> file is too large to read so I want to be able to scroll through it >> with the arrow key or something like that. I am not using GUI. > > In that case you need to write some screen handling code to > do the paging. Ideally that means working out how many lines > the screen can display then displaying the data in chunks of > that size. Basic screen handling can be as simple as hit return > to contnue. But if you want to page up as well then you need a > bit more. Here is some pseudo (ie. incomplete and untested) code: > > data = myfile.readlines() > size = 25 ## get real screen length here! > top = 0 > > while True: > try: > for line in data[top:top+size]: > print line > key = raw_input("N for Next page, P for Previous page, Q to Quit") > if key in 'Nn': top += size > elif key in 'Pp': top -= size > elif key in 'Qq': break > except IndexError: break > > Obviously you can make the control keys as sophisticated as you want! > > HTH, > > Alan G. > > -- Mike Hoy ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Scrolling through output in shell
Forwarding to the group. Please use Reply All when responding. - Original Message From: Mike Hoy <[EMAIL PROTECTED]> To: Alan Gauld <[EMAIL PROTECTED]> > I'm writing a program that reads a text file onto the screen. The text > file is too large to read so I want to be able to scroll through it > with the arrow key or something like that. I am not using GUI. In that case you need to write some screen handling code to do the paging. Ideally that means working out how many lines the screen can display then displaying the data in chunks of that size. Basic screen handling can be as simple as hit return to contnue. But if you want to page up as well then you need a bit more. Here is some pseudo (ie. incomplete and untested) code: data = myfile.readlines() size = 25 ## get real screen length here! top = 0 while True: try: for line in data[top:top+size]: print line key = raw_input("N for Next page, P for Previous page, Q to Quit") if key in 'Nn': top += size elif key in 'Pp': top -= size elif key in 'Qq': break except IndexError: break Obviously you can make the control keys as sophisticated as you want! HTH, Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Scrolling through output in shell
On Sun, Nov 16, 2008 at 1:21 PM, Mike Hoy <[EMAIL PROTECTED]> wrote: > I'm writing a small program that writes to a text file. I want to be > able to view the contents of the text file inside of shell. But the > file is too large for a small shell window. Is there a way for the > user to 'scroll' through the contents of file that has been read into > the program? I noticed that on the man pages that you can do that > although I'm sure it's not written in python. Do I need to find a new > language to write this in? Maybe use a different language for the > output and still use python? Any help appreciated. > > -- > Mike Hoy > http://www.mikehoy.net As Alan has noted, your request isn't perfectly clear. So, I'm going to change your question and answer it. If I picked the wrong question, please be more explicit in your next reply. Question: How can I read a text file from the command line if the file is too large to fit on the screen at once? Answer: more or less If you're in Windows, you can use the more command: more file.txt That will allow you to scroll up and down. If you're on pretty much any other OS, you can use more or less. I prefer less, because it has more features. You use it the same way you use more: less file.txt ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Scrolling through output in shell
"Mike Hoy" <[EMAIL PROTECTED]> wrote I'm writing a small program that writes to a text file. I want to be able to view the contents of the text file inside of shell. But the file is too large for a small shell window. Can you explain a bity more about what you are doing? Which shell are you talking about? Are you using IDLE or some other IDE? Or is it the Unix shell? Is there a way for the user to 'scroll' through the contents of file that has been read into the program? Only if you provide a window for the output to be displayed within. Are you writing a GUI? Or are you using the console for output? If the latter you can build a paging facility to display the file a page at a time. I noticed that on the man pages that you can do that although I'm sure it's not written in python. Which man pages? How are you viewing them? Do I need to find a new language to write this in? Maybe use a different language for the output and still use python? Any help appreciated. No you can do anything like this in Python, but I suspect you may be confused about the difference between Python the language and the Python interactive prompt. The >>> prompt is not where you write programs, it is only for experimenting to find out how features work, or for testing modules. If you want to write a program you should do so as a separate file (perhaps using IDLEs File-New menu) and run it once finished) outside of IDLE. But I may be misunderstanding things. Can you answer the questions above to clarify exactly what you are doing? -- Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Scrolling through output in shell
I'm writing a small program that writes to a text file. I want to be able to view the contents of the text file inside of shell. But the file is too large for a small shell window. Is there a way for the user to 'scroll' through the contents of file that has been read into the program? I noticed that on the man pages that you can do that although I'm sure it's not written in python. Do I need to find a new language to write this in? Maybe use a different language for the output and still use python? Any help appreciated. -- Mike Hoy http://www.mikehoy.net ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor