[Tutor] exception about "ctrl+c"

Joel Goldstick joel.goldstick at gmail.com
Mon Jan 9 13:41:24 CET 2012


On Mon, Jan 9, 2012 at 7:24 AM, daedae11 <daedae11 at 126.com> wrote:
> I want to catch the "ctrl+c" exception. My program is as following. But when
> I run my script and press "ctrl"+"c", the  program output nothing. I don't
> know where did I go wrong. Please help me. Thank you!
>
> def safe_input(prompting):
>     try:
>         return raw_input(prompting);
>     except KeyboardInterrupt, error:
>         print error;
>         return None;
>
> def main():
>     a = safe_input("input any thing!\n");
>     print a;
>
>
> if __name__ == '__main__':
>     main();
>
> ________________________________
> daedae11
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
  python ctl-c.py
  input any thing!
  fdsaj
  fdsaj
  python ctl-c.py
  input any thing!
  ^C
  None

I just got this from your code.  Seems to work on python 2.65, linux

Are you running it from a command line like:  python ctl-c.py
or are you running in a python shell?  If you are in a shell it might
be consuming the ctl-c before your program can


-- 
Joel Goldstick


More information about the Tutor mailing list