cmd module documentation lying?
pwang99c
pzw1 at cornell.edu
Fri Dec 7 01:21:57 EST 2001
i'm using the cmd.Cmd interactive interpreter loop for the first time, using documentation out of the latest _Python Essential Reference_. (i looked on the web page http://www.python.org/doc/current/lib/Cmd-objects.html but there wasn't as much detail.)
there seems to be a disparity between documentation and actual code behavior with regard to the return values of command functions (do_*). according to the book, only negative return values are construed as errors and cause the cmdloop() function to return; however, in practice, any non-zero value seems to do this.
--------------------------------------------
import cmd, string
class myInterpreter(cmd.Cmd):
def do_blah0(self, argline):
return 0
def do_blah1(self, argline):
return 1
def do_blahNeg(self, argline):
return -1
def do_blahArb(self, argline):
return string.atoi(argline)
x = myInterpreter()
x.cmdloop()
--------------------------------------------
when the above code is run, one can type "blah0" all day long and the interpreter continues running; if one tries running any of the other functions (or blahArg with a non-zero value), the interpreter loop exits.
so... is this a known problem, or am i misunderstanding something? should i be emailing David Beazley about his book? or is there some place for more up-to-date documentation on the cmd module? (besides the source itself. :-)
TIA,
peter
More information about the Python-list
mailing list