custom autocomplete for cmd module using raw

I have a project using Python 2.7, with the Cmd Module.

I have tab complete working with the existing commands using the complete_* methods.

However, I would like to extend that a little, for instance we have a command called 'ask'. Rather than having everything input on a single line, I have a few questions following using raw_input.

ie

    def do_ask(self,args):
    name = raw_input('What is your name: ')
    bird = raw_input('What is your favourite Bird: ')
    reptile = raw_input('What is the best reptile: ')

    print 'I like %s too!' % reptile

if I use 'complete_ask' it will only work when the word 'ask' is prepended to the answer, in the above example I'd have to set my favourite reptile as "ask gecko", rather than gecko.

Ideally, the dictionary for tab complete I will be using will change for each of the three questions.

I am not an expert in readline (or Python), so I am not sure if I utilize an example found here (like found in other questions) if it will break the Cmd module's existing tab completion.

In short, how can I have a custom tab complete for each raw_input without having to type the command again?

Sorry - new here so if I am unclear my bad.

I should add - we can make an assumption that I have three dictionaries with the words I would like to use with tab complete.

链接地址: http://www.djcxy.com/p/9666.html

上一篇: 多个模型错误

下一篇: 自定义自动完成cmd模块使用raw