python – Cmd模块:在第一个单词上完成

我使用completedefault(
see the doc)完成Cmd模块.但似乎只有在第一个词之后才会被调用.

def completedefault(self,text,line,begidx,endidx):                                          
     print('completedefault is called')                                                      
     return ['foo','bar']

输出:

(Cmd) f<Tab><Tab>
(Cmd) foo f<Tab><Tab>
completedefault is called
foo bar

如何更改此行为,甚至在第一个单词上调用它?

最佳答案 答案很简单:Cmd.completenames.更多信息
here.类似的问题
here.

点赞