New submission from Steven D'Aprano <steve+pyt...@pearwood.info>:
When asking for user input, it is often very helpful to be able to pre-populate the user's input string and allow them to edit it, rather than expecting them to re-type the input from scratch. I propose that the input() built-in take a second optional argument, defaulting to the empty string. The first argument remains the prompt, the second argument is the initial value of the editable text. Example use-case: pathname = "~/Documents/untitled.txt" pathname = input("Save the file as...? ", pathname) On POSIX systems, this can be done with readline: import readline def myinput(prompt, initial=''): readline.set_startup_hook(lambda: readline.insert_text(initial)) try: response = input(prompt) finally: readline.set_startup_hook(None) return response but it requires readline (doesn't exist on Windows), and it clobbers any pre-existing startup hook the caller may have already installed. ---------- messages: 344701 nosy: steven.daprano priority: normal severity: normal status: open title: Pre-populate user editable text in input() type: enhancement versions: Python 3.9 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue37161> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com