A question about Cmd Class

yuan zheng tsinghuayuan86 at gmail.com
Thu Mar 10 01:54:57 EST 2011


Thanks.

I understand your code , and print it.

*Before replace:*
`~!@#$%^&*()-=+[{]}\|;:'",<>/?
*
After replace:*
`~!@#$%^&*()=+[{]}\|;:'",<>/?


Certainly, the charactor ‘-’ has been deleted from delims.
But there is nothing effect on my program after adding the code.

My shell:
---------------------------------------------------------------------------------------------------------------------
<Mycmd> l<TAB>
list-bp        list-machines  list-modules   list-options   load-conf
log-bus        ls
<Mycmd> list-<TAB>
........ NOTHING...
---------------------------------------------------------------------------------------------------------------------

The mean is that when I input "l", and then hit "TAB", it can list all optional
cmd.
But when I input "list-", and then hit "TAB", there is nothing.




thanks,
yuanzheng.


2011/3/9 Dog Walker <thudfoo at gmail.com>

> On Monday 2011 March 07 18:41, yuan zheng wrote:
> > 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.
> >
>
> That is because the readline module uses '-' as one of its stop characters.
> You can try this code I used:
>
> # PyPI package names can contain hyphens.
> # readline interprets a hyphen as a word boundary.
> # We need to remove the hyphen from readline's
> # word boundary delimiters so that our findpkg
> # command can complete on package name.
> import readline
> delims = readline.get_completer_delims(  )
> delims = delims.replace('-', '')
> readline.set_completer_delims(delims)
> del delims
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110310/286c515b/attachment-0001.html>


More information about the Python-list mailing list