default variable value and cmd module

Duncan Booth duncan at NOSPAMrcp.co.uk
Tue Sep 10 16:00:34 CEST 2002


"konghyeogjun" <toto2001 at hananet.net> wrote in 
news:hmmf9.201$GH5.711 at news.hananet.net:

> This sample using 'cmd' module do not prints default variable value, 5.
> 
> import cmd
> class x(cmd.Cmd):
>     def do_y(self, value = 5):
>         print value
> z = x()
> z.cmdloop()
> 
> but, the following sample prints '5'. why don't the sample above prints?

>From the documentation for cmd.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.

So the value passed to do_y as 'value' is whatever you type on the rest of 
the command line after your 'y' command. It doesn't print 5 because the 
default value is always overridden, even if you don't type anything after 
the command name.


-- 
Duncan Booth                                             duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?



More information about the Python-list mailing list