On 04/01/2014 07:58 AM, Steven D'Aprano wrote:
(I'm talking about Python 3 input, previously known as raw_input.)
I often have the need to include a default or initial value when asking the user for input. In other words, I'd like to call this:
input("What is the fish of the day? ", "trout a la creme")
and have the prompt be "What is the fish of the day? " and the initial value in the edit buffer be "trout a la creme", fully editable with whatever line editing tools are available on the user's system. There are work-arounds for this lack, but they don't make a nice clean UI.
Under Linux, with readline, I can implement this relatively simply:
One of the things I first looked for when learning python was a get_key_press function. Line input (or whole file input) is great for files, and can make reading data much faster than single character input. But for user input, single char input can be useful. If we could read the keyboard directly with a get_key_press function, then your request along with making curses cross platform, may be fairly easy to do. (The cross platform get_key_press function is the hard part.) Cheers, Ron