cmd.Cmd asking questions?

Tim Chase python.list at tim.thechases.com
Mon Nov 28 07:12:06 EST 2011


Are there best-practices for creating wizards or asking various 
questions (whether yes/no or text/numeric entry) in a cmd.Cmd 
class? Something like the imaginary confirm() and get_string() 
methods here:
 class MyCmd(cmd.Cmd):
 def do_name(self,line):
 s = get_string(prompt=line, default="Whatever")
 ...
 def do_save(self,line):
 if os.path.isfile(line):
 if not confirm("%r exists. Continue?", True): return
 self.save(line)
 def save(self, filename):
 ...
I can monkey with printing messages and using raw_input(), but 
I'd like to know if there's a better way (such as something 
interacting with readline for 
text-entry-with-history-and-completion, or raw-character input 
for Y/N answers rather than the need to hit <enter>, making it 
feel more uniform),
Thanks,
-tkc


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /