Exploratory query

Skip Montanaro skip at pobox.com
Tue Aug 5 22:09:56 CEST 2003


>>>>> "Don" == Don Todd <spammenot at ningunaparte.com> writes:

    Don> In article <mailman.1060056189.31290.python-list at python.org>, Skip Montanaro wrote:
    >> 
    Don> Would python allow me to run flist and use its output, or would I
    Don> need to re-write flist? The idea is to keep something on the screen
    Don> and poll the mailboxes every n seconds and update the display.
    >> 
    >> You can do this quite easily.  Presuming you just want to display flist's
    >> output for now, but maybe mangle it later, you can probably get away with
    >> something simple like this:
    >> 
    >> import time
    >> import commands
    >> 
    >> while True:
    >> status, output = commands.getstatusoutput("flist")
    >> if status != 0:
    >> print "flist barfed... exiting"
    >> # right here you could massage output
    >> print output
    >> time.sleep(300)         # five minutes
    >> 
    >> Skip

    Don> Thanks, Skip! That pretty much does what I want; I modified it to
    Don> do "flist mailbox1", "flist mailbox2" etc.

Also, note that I forgot the break statement in the exit branch.  Should
have been:

    if status != 0:
        print "flist barfed... exiting"
        break

    Don> Is there a way to run this in a terminal and have it uptate the new
    Don> over the old? I'm thinking it would be sweet to run it in
    Don> tranparent terminal. Perhaps I'll look into using a gui, too.

Sure.  There are a couple ways to do it.  The crude way might just be to put


    commands.getstatusoutput("clear")

at the top of the list.  The cleaner way would probably be to use the
curses module.  I've no experience to make any suggestions, but the curses
module docs at

    http://www.python.org/doc/current/lib/module-curses.html

have a link to Andrew Kuchling's "Curses with Python" tutorial.

Skip






More information about the Python-list mailing list