Starting value with raw_input

D

David Hirschfield

Does the raw_input built-in function allow giving an initial value that
the user can edit?
Perhaps by using the readline module?

I want to do something so that I can provide the user a default value
they can edit as they wish at the prompt:

result = raw_input("Enter value: ")
#### Somehow output default value so prompt looks like:

Enter value: default

they can edit "default" to whatever they want, and I'll get the result.

Does what I'm asking make sense?
-Dave
 
S

Steve Bergman

Kinda ugly, and I lifted it from an old post, but this should work:

import readline
readline.set_startup_hook(lambda:
readline.insert_text('supercalifragilisticexpialidocious'))
try:
new_value = raw_input()
finally:
readline.set_startup_hook(None)
 

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

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,279
Latest member
LaRoseDermaBottle

Latest Threads

Top