Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #16321
| Date | 2011-11-28 06:12 -0600 |
|---|---|
| From | Tim Chase <python.list@tim.thechases.com> |
| Subject | cmd.Cmd asking questions? |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3091.1322482335.27778.python-list@python.org> (permalink) |
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
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
cmd.Cmd asking questions? Tim Chase <python.list@tim.thechases.com> - 2011-11-28 06:12 -0600
csiph-web