cmd.Cmd asking questions?

T

Tim Chase

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top