Breaking out of a while loop with a key press?
Carl Banks
imbosol-1049135186 at aerojockey.com
Mon Mar 31 21:35:56 CEST 2003
Richard wrote:
> Can anyone suggest a simple way of detecting a key press and existing the
> program? I have a program which at the moment uses a while True: statement.
> However this is not ideal as I have to close down the console window to
> exist the program. Can anyone tell me the proper way of doing this? So that
> a CTRL-C, for example, can quit the program correctly?
We would have to know what kind of console this is to answer this. Is
it curses? Some kind of GUI widget? Things that provide consoles
within Python often do not trap Control-C, so you'd have to do it
yourself. And that, of course, depends highly on what sort of console
you're talking about.
--
CARL BANKS
More information about the Python-list
mailing list