使用Python的readline
绑定。例如,
import readline
def completer(text, state):
options = [i for i in commands if i.startswith(text)]
if state < len(options):
return options[state]
else:
return None
readline.parse_and_bind("tab: complete")
readline.set_completer(completer)
官方模块文档没有更多详细信息,请参阅readline文档以获取更多信息。