python raw_input中使用tab键补全命令
用 readline, 以下是一个简单的例子import readlineCMD = ['foo1', 'foo2', 'bar1', 'bar2', 'exit']
def completer(text, state):
options =
if state < len(options):
return options
else:
return None
readline.parse_and_bind("tab: complete")
readline.set_completer(completer)
while True:
cmd = raw_input('==> ')
if cmd=='exit':
break
print(cmd)测试:==> <TAB><TAB>
bar1 bar2 exit foo1 foo2
==> b<TAB>
==> bar
==> bar<TAB><TAB>
bar1 bar2
==> bar1
bar1
==> exit
页:
[1]