A question about Cmd Class

yuan zheng tsinghuayuan86 at gmail.com
Mon Mar 7 21:41:01 EST 2011


Hello, everyone:

    I encouter a question when implementing a commmand line(shell).
I have implemented some commands, such as "start", "stop", "quit",
they are easily implemented by "do_start", "do_stop" and "do_quit".
there are no troubles.
     But I want to implement some commands like these "list-modules",
"show-info". There is a character "-" among the string. So I can't easily
use "do_list-modules", because the name is invalid. I attempt another
ways, add a sentense in function "cmd.onecmd":
-------------------------------------------------------
   def onecmd(self, line):
        line = line.replace("-", "_")         # I add
    ...
-------------------------------------------------------
Then, I can use "do_list_modules" to mach "list-modules" command. But in
this way, completion cannot work correctly. If I input "list-", and then
"tab",
it would not complete.

If my way is correct when encoutering commands with "-" ?
If it's correct, how can I implement completion to work correctly?



thanks,
yuanzheng.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110308/8703d860/attachment.html>


More information about the Python-list mailing list