Wait for a keypress before continuing?
steve+comp.lang.python at pearwood.info
Mon Aug 8 02:27:59 CEST 2011
John Doe wrote:
> My program does not need a prompt, it just needs to wait for any
> key to be pressed before it continues. This is in Windows.
> while not char:
> That doesn't delay anything here.
Works perfectly for me. You don't need the while loop, since getch blocks
until a key is pressed.
Rather than making arbitrary changes to the code, try printing char after
the loop exits and see what it contains. That may give you a hint as to
what is going on.
Also, are you using an IDE? If so, it could very well be interfering with
the keyboard buffer, for its own purposes. E.g. in IDLE 2.6.2, if I call
getch it *immediately* returns without blocking:
More information about the Python-list