cmd module question

jedi at ccrypt.net jedi at ccrypt.net
Fri May 18 02:20:34 EDT 2001


Hi there.  Newbie for both python and programming in general.

I'm writing a simple mail client and I've hitting a snag.  I've written
the following function to get mail from the unix mail file and dump each
message into a list:

def do_get(self):
	while 1:
		msg = mb.next()
		 if not msg:
			break
		msg["body"] = msg.fp.read()
		list.append(msg)

I get the following error when I test it:

bash-2.05$ python read.py
Reader:get
Traceback (most recent call last):
  File "read.py", line 36, in ?
    read.cmdloop()
  File "/usr/local/lib/python2.1/cmd.py", line 86, in cmdloop
    stop = self.onecmd(line)
  File "/usr/local/lib/python2.1/cmd.py", line 124, in onecmd
    return func(arg)
TypeError: do_get() takes exactly 1 argument (2 given)


I've run my code through the interpeter and read through the cmd.py module
file to figure out what I'm doing wrong..  I can't seem to locate where
it's sending 2 args.

TIA

Below is the full 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()






More information about the Python-list mailing list