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
[Tutor] Convert a text logfile to RSS xml.
Hi, I was just thinking how to improve our opensource Website and was wondering if there is an easy way to convert say an IRC logfile to an rss feed using pyton? I was thinking about running the script with cron that will scan the latest logfile for the day and convert it to rss xml std it would overwrite the rss feed file everytime and then when a new day starts the xml file is overwritten. How would you do this? and do you have any suggestions? I was also thinking of importing the logfiles into a small sqllite db and then convertinbg the sqldb into a feed. Regards Lance ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] /not/ instanciating
On Sun, Nov 16, 2008 at 2:57 PM, spir <[EMAIL PROTECTED]> wrote: > * Why, then, is __init__ still executed when the instanciated object is > 'manually' returned? What's the use of that feature? The manual (http://www.python.org/doc/2.5.2/ref/customization.html) says: "If __new__() returns an instance of cls, then the new instance's __init__() method will be invoked like "__init__(self[, ...])", where self is the new instance and the remaining arguments are the same as were passed to __new__(). " That seems to explain why you're seeing what you're seeing. I don't know how you would avoid that if that's not the behavior you want, though. I suppose you could then repeat your check of the type of source in __init__, just like you did in __new__ to avoid re-initializing. -- Jerry ___ 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] Python 2.5 on a Win 98 Machine
On Sun, Nov 16, 2008 at 11:12 PM, Wayne Watson <[EMAIL PROTECTED]> wrote: > I'm attaching the screen image the user of the program rcvd. If you'd like > me to place it somewhere that everyone can see it, I'll do so if you provide > the URL. You can copy and paste from the dos prompt, you don't have to post screen shots. > Is there something worthwhile pursing with this screen message? If not, then > I'm just going to turn his problem over to the sponsoring organization, and > let them worry about it. Apparently it is not finding a DLL that it needs, either matplotlib._path or something required by _path. I would look for the _path module, if you have it and it is Python, look at what it imports. Do you have numpy installed on this machine? It is required by matplotlib. What happens if you try to import numpy? Please reply to the list, not to me personally. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor