Problem regarding command line completion

Rajashree Thorat rajashree.thorat16 at gmail.com
Mon Oct 3 08:00:25 EDT 2011


Hi All,

Please can anyone help me in resolving following problem.

import cmd
class CmdLineApp(cmd.Cmd):

        def do_grep(self, line):
                print line

        option = ["--ignore-case",
"--invert-match","--word-regexp","--line-regexp"]
        def complete_grep(self, text, line, begidx, endidx):
                return [i for i in CmdLineApp.option if i.startswith(text)]

interpreter = CmdLineApp()
interpreter.cmdloop()

In above program I want to do command line completion (or tab completion).
If the elements of option list starts with special character such as
'-', '@', '#', '--' , then it is giving me output like

(Cmd) grep
grep
(Cmd) grep ------

instead of

(Cmd) grep --
--ignore-case  --invert-match  --word-regexp  --line-regexp

How I can handle this special characters?


Thanks & Regards
Rajshree Thorat
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20111003/178e4a36/attachment.html>


More information about the Python-list mailing list