Asking the user a question and giving him a default answer he can edit

levander levander at mindspring.com
Sun Jul 31 00:34:47 EDT 2005


I'm trying to figure out the python readline module to see if it will
do this.

Basically, I've got a bunch of questions to ask a user, the vast
majority of which, the answer will only vary by the last few
characters. What I'd like to do is every time the user is asked a
question, give him the default answer as just whatever he answered last
time. But, I want him to be able to edit this default answer.  And, the
editted answer is what I want to operate on inside my program.

raw_input() lets the user edit the prompt I send.  But, internally, it
must ignore the backspace key or something.  Because, it only returns
new letters that the user has typed in.  Not anything that he has
backspaced over or deleted.

You can edit whatever you put out there with raw_input, but it's like
internally that function ignores the backspace key, and just returns
whatever new characters the user types.

Basically, I want to the user a line editor, with a default value
already populated.

Anybody know how to do something like this?

I've been playing around with doing it in bash, figuring I can use
popen to spawn the process if I can figure it out, but haven't figured
it out yet.




More information about the Python-list mailing list