Thread: cmd module

    #1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    67
    Rep Power
    12

    Question cmd module


    Has any of you ever used the cmd module? I read the document at the Python homepage, but I didn't really understand how to use the module. If some could show me some code, I'd really apprieciate it.
    Before you criticize someone, walk a mile in their shoes, that way when you do criticize them, you're a mile away and you have their shoes!
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    Somewhere over the Rainbow
    Posts
    128
    Rep Power
    12
    hope works..

    Code:
     #!/usr/local/bin/python
    
    import cmd
    import mailbox
    
    userbox='/var/mail/jedi'
    list=[]
    mb=mailbox.UnixMailbox(open(userbox))
    
    class Reader(cmd.Cmd):
    
            def __init__(self):
                    cmd.Cmd.__init__(self)
                    self.prompt = "Reader:"
    
            def help_get(self):
                    print "Gets all the messages in your mailbox."
    
            def do_get(self):
                    while 1:
                            msg = mb.next()
                            if not msg:
                                    break
                            msg["body"] = msg.fp.read()
                            list.append(msg)
    
            def help_quit(self):
                    print "Quits you out of Reader."
    
            def do_quit(self, line):
                    print "Exiting..."
                    sys.exit()
    
    if __name__ == '__main__':
            readbox = Reader()
            readbox.cmdloop()
    Last edited by Gerardoj; November 30th, 2003 at 01:21 AM.

IMN logo majestic logo threadwatch logo seochat tools logo