Providing 'default' value with raw_input()?

keirr keir.robinson at
Thu Dec 22 18:08:13 CET 2005

planetthoughtful wrote:
> I'm wondering if it's possible, using raw_input(), to provide a
> 'default' value with the prompt?
def get_input_with_default(default, prompt=">>> "):
    result = raw_input('['+str(default)+'] '+str(prompt))
    if result == "": result = default
    return default

> I would like to include the ability to edit an existing value (drawn
> from an SQLite table) using a DOS console Python app, but my gut
> feeling from reading what I can find about raw_input() is that it only
> allows you to provide a prompt, not a default value as well.
I think it is the editing part that is going to give you a hard time.
curses and readline might be some help if you were on a Unix platform.
I can't think of any way to provided a editable  value at the dos

All the best,

More information about the Python-list mailing list