我使用PythonPromptToolkit进行自动补全,它在单次补全时工作得非常好。但我需要使用嵌套补全。从DOCS中考虑下面的例子:
from prompt_toolkit import prompt
from prompt_toolkit.completion import NestedCompleter
completer = NestedCompleter.from_nested_dict(
{
"show":
{"version": None,
"clock": None,
"ip": {"interface": {"brief": None}}
},
"exit": None,
}
)
def main():
text = prompt("Type a command: ", completer=completer)
print("You said: %s" % text)
if __name__ == "__main__":
main()
虽然它确实有效,但它只在我使用空格作为分隔符(即,在单词之间保留空格)来分隔单词时有效,如
show version
。但是我想使用'\\' or '/'
(取决于操作系统)作为分隔符,所以它就像show/ip/interface/brief
(类似于shell路径完成的工作方式)。我知道您可以这样做,但我不知道如何做?。非常感谢您的帮助
目前没有回答
相关问题 更多 >
编程相关推荐