Is it possible to prefill a input() in Python 3's Command Line Interface? Is it possible to prefill a input() in Python 3's Command Line Interface? python python

Is it possible to prefill a input() in Python 3's Command Line Interface?


If your Python interpreter is linked against GNU readline, input() will use it. In this case, the following should work:

import readlinedef input_with_prefill(prompt, text):    def hook():        readline.insert_text(text)        readline.redisplay()    readline.set_pre_input_hook(hook)    result = input(prompt)    readline.set_pre_input_hook()    return result