[Tutor] Introduction to the cmd Module

Alan Colburn aicolburn@yahoo.com
Fri, 27 Sep 2002 10:50:37 -0700


I picked up a copy of Lutz & Ascher's 'Learning Python' book recently and,
while looking through it, learned about the cmd module. I'd love to start
using it, but I'm having some difficulties. I'm not quite sure what
information I'm missing, but I can't seem to get simple tests to work
properly (...and I couldn't really understand the online documentation :-)

For example, consider this simple script:
import cmd
class Test(cmd.Cmd):
    def __init__(self):
        cmd.Cmd.__init__(self)
        self.prompt="% "
    def do_printHello(self):
        print 'hello'
x=Test()
x.cmdloop()

The new prompt appears, but the printHello command generates an error
(do_printHello takes 1 argument, 2 given).

Before posting here, I looked around a bit to try to find answers online
somewhere, but ended up more confused than before I started :-) It seems as
though sometimes people pass an added variable, "argline" into their class
method definitions, and sometimes they don't. The scripts work fine for me
when I add an "argline," but I don't really know what it is or why I'm doing
it.

Anybody feel like a brief tutorial? :-)

As always, my thanks to you all. -- Al C.