On 2012/01/09 02:24 PM, daedae11 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@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
def safe_input(prompting):
try:
return raw_input(prompting)
except KeyboardInterrupt:
print 'KeyboardInterrupt Issued'
return None
That will work as intended, if you had your original `except
KeyboardInterrupt, error:` and did a `print repr(error)` afterwards you
will see it does not contain an error message as you perhaps wanted.
Also, Python does not require semi-colons to denote the end-of-line. It
can be used if you want to have multiple statements on a single line though.
--
Christian Witts
Python Developer
//
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor