Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #16321 > unrolled thread

cmd.Cmd asking questions?

Started byTim Chase <python.list@tim.thechases.com>
First post2011-11-28 06:12 -0600
Last post2011-11-28 06:12 -0600
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

  cmd.Cmd asking questions? Tim Chase <python.list@tim.thechases.com> - 2011-11-28 06:12 -0600

#16321 — cmd.Cmd asking questions?

FromTim Chase <python.list@tim.thechases.com>
Date2011-11-28 06:12 -0600
Subjectcmd.Cmd asking questions?
Message-ID<mailman.3091.1322482335.27778.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web