How can I extend raw_input to provide user w/ default input string?

Edoardo ''Dado'' Marcora marcora at colorado.edu
Thu Jun 7 11:27:08 EDT 2001


Thanx Paul for your helpful suggestion. However, I was thinking about
presenting the user with a default input and give him/her the ability to
edit it. Maybe I should think about using Tkinter if this is impossible to
do using a console interface.

"Paul Winkler" <slinkp23 at yahoo.com> wrote in message
news:3B1F0D82.DB10E008 at yahoo.com...
> Edoardo ''Dado'' Marcora wrote:
> >
> > I am wondering if it is possible to provide the user with a default
input
> > string using raw_input or similar function.
>
> If you just want to show the default, that could be done like this:
>
> import sys
>
> def raw_input_with_default(prompt, default="yes"):
>     sys.stdout.write(prompt + " [%s] " % default)
>     result = sys.stdin.readline().strip()
>     result = result or default
>     return result
>
>
> So if they don't type any non-whitespace characters before hitting return,
> default will be used.
>
> If you want them to be able to *edit* the printed default string... I have
no
> idea.
>
> HTH,
>
> PW





More information about the Python-list mailing list