Show default value for editing on Python input possible?

I'm assuming you mean from the command-line. I've never seen initial values for command line prompts, they're usually of the form:

Folder [default] : 

which in code is simply:

res = raw_input('Folder [default] : ')
res = res or 'default'

Alternatively, you can try to do something using the curses module in Python.


The standard library functions input() and raw_input() don't have this functionality. If you're using Linux you can use the readline module to define an input function that uses a prefill value and advanced line editing:

import readline

def rlinput(prompt, prefill=''):
   readline.set_startup_hook(lambda: readline.insert_text(prefill))
   try:
      return input(prompt)  # or raw_input in Python 2
   finally:
      readline.set_startup_hook()

Tags:

Python

Input