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

L

levander

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.
 
M

Michael Hudson

levander said:
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.

Something like this?

/>> def f():
|.. readline.set_startup_hook(lambda :readline.insert_text('aaa'))
|.. return raw_input()
\__
Basically, I want to the user a line editor, with a default value
already populated.

Or you could use my pyrepl package (see google for that).

Cheers,
mwh
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top