Reputation: 981
(Python 3.3.4)
I am currently using the cmd module to build an application, but for some reason I just can't get the completion to work correctly. Whenever I hit tab
it just indents my input string!!
So, if I have something like this:
(MyShell)>> ta«cursor here»
I hit «tab» and get this:
(MyShell)>> ta «cursor here»
I have tried in IDLE, the Windows Power Shell and in the Python interpreter itself, I guess... Neither the completion of commands nor the completion of arguments work!!
The code is this:
class MyShell(cmd.Cmd):
def __init__(self):
cmd.Cmd.__init__(self)
self.intro = "Welcome to MyShell test.\nPowered by Rodrigo Serrão"
self.prompt = "(MyShell)>>"
def do_talk(self, text):
print("Hello")
stuff = ["blabla", "bananas!", "noodles"]
def complete_talk(self, text, line, s, e):
if text:
return [i for i in stuff if i.startswith(text)]
else:
return stuff
MyShell().cmdloop()
I have read some questions about this, including this one: Python Cmd Tab Completion Problems
And it may have to do with that readline
thing. I tried to import it, but apparently I don't have it.
Upvotes: 3
Views: 2912
Reputation: 328
if it is a problem of your check this approach.
Go to run and type regedit.
Go to LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor.
And change the PathCompletionChar value to 9. Usually it is 40. That means your current auto completion key is not the TAB key. After you assign the value 9 close the window and restart the CMD.
Now this would be fixed. Auto completion of paths would be working fine by the TAB key.
Upvotes: 5
Reputation: 147
So I'm writing a interactive shell app on Python too, to get auto completion working, install pyreadline, the readline module is Unix specific.
If you don't know how install just execute the following line:
pip install pyreadline
Upvotes: 1