cmd module question

jedi at ccrypt.net jedi at ccrypt.net
Fri May 18 13:42:03 EDT 2001


added the second arg and it worked great.  I had previously used the cmd
module for simple todo list editor (as my first adventure into python) and
I used the same syntax and it didn't gack at me like this did.

thanks for your help.

On Fri, 18 May 2001, Daniel Dittmar wrote:

> >   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.
>
> All do_* methods must be declared as
>
> def do_something (self, strarg = None):
>
> strarg will contain the remainder of the input.
>
> You don't see a call with two argumentes because of the line
>
> func = getattr(self, 'do_' + cmd)    # in cmd.py
>
> The callable object returned from getattr is already bound to your object,
> so the self parameter is implicit in the call.
>
> Daniel
> --
> Daniel Dittmar
> daniel.dittmar at sap.com
> SAP DB, SAP Labs Berlin
> http://www.sapdb.org/
>
> <jedi at ccrypt.net> wrote in message
> news:mailman.990166766.17981.python-list at python.org...
> > 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()
> >
> >
> >
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>





More information about the Python-list mailing list