Cmd Module

Fredrik Lundh fredrik at
Wed Nov 23 09:21:59 CET 2005

Godwin Burby wrote:

>         I was just curious about using the cmd module for building my
> own command line interface. i saw a problem. The script is as follows:

it helps if you include the code you were running, instead of some
approximation of it.

  File "test", line 10
    if passwd = 'godwin': print "You are a valid user"
SyntaxError: invalid syntax

Traceback (most recent call last):
  File "<stdin>", line 4, in ?
NameError: name 'cmd' is not defined

> The interpreter reports that the first argument to super should be a
> type rather than a class object and for the do_login function it says
> that function needs only one argument but two are given. I solved the
> above errors by adding the following code:
> Cmd.__init__(self)
> def do_login(self,passwd='godwin')
> But i know that my first code should work without any problems or is
> there a problem with it.

super() only works for new-style classes.

the second argument problem is because do_ methods are called with
a second argument:

    >>> import cmd
    >>> help(cmd)
    Help on module cmd:
    3. A command `foo' is dispatched to a method 'do_foo()'; the do_ method
       is passed a single argument consisting of the remainder of the line.

(if you type "login", you get an empty string.  if you type "login foo", you get
the string "foo".  etc).


More information about the Python-list mailing list