Breaking out of a while loop with a key press?
Gilles Lenfant
glenfant at NOSPAM.bigfoot.com
Mon Mar 31 11:51:20 EST 2003
"Richard" <richardd at hmgcc.gov.uk> a écrit dans le message de news:
3e885ad5 at mail.hmgcc.gov.uk...
> Hi,
>
> 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?
Catch the KeyboardInterrupt exception.
>
> Cheers
>
> Richard
>
>
More information about the Python-list
mailing list