Why doesn't Python include non-blocking keyboard input function?

Chris Angelico rosuav at gmail.com
Tue Oct 25 07:25:23 EDT 2016


On Tue, Oct 25, 2016 at 9:02 PM, BartC <bc at freeuk.com> wrote:
>> raw_input('Press the Enter key to continue... ')
>
>
> Which doesn't work on Python 3. So even here, making it easy by using
> line-input, it's not so straightforward.

So you use input() instead. Big deal. The concept is still the same.

>> If you are doing something more complex, waiting on different keys to do
>> different things,
>
>
> You mean, something as sophisticated as press Enter to continue, or Escape
> to quit? Or Page Up and Page Down?

Enter to continue or Ctrl-C to quit. Just as easy.

> But why the need to have to use someone else's massive great wheel? Both
> Curses and wxPython are completely over the top IMO for something so
> fundamental.

Fundamental? What exactly is fundamental about key-based input? Much
more fundamental is character-based input, where you request *text*
from the user. How often do you care whether someone pressed '1' on
the top row as compared to '1' on the numeric keypad? How often do you
actually need to handle Backspace as a key, rather than simply having
it remove one character? Do you actually want to distinguish between
typed keys and pasted text? Much more commonly, you simply ask for
input from the user, and get back a line of text. The user might have
edited that line before submitting it, and that's a feature, not a
bug.

When you want more flexibility than "Enter to continue or Ctrl-C to
abort", it probably *is* time to get curses or a GUI toolkit, because
you're doing something that's fundamentally different from "request
text from the user".

ChrisA



More information about the Python-list mailing list