here is a test case.
try:
    targ = raw_input("Please enter target: ")
except KeyboardInterrupt:
    print "Cancelled"
print targ
My output is as follows when I press ctrl+c-
NameError: name 'targ' is not defined
My intention is for the output to be "Cancelled". Any thoughts to as why this happens when I attempt to catch a KeyboardInterrupt during raw_input?
Thanks!
In above code, when exception raised, targ is not defined. You should print only when exception is not raised.
try:
    targ = raw_input("Please enter target: ")
    print targ
except KeyboardInterrupt:
    print "Cancelled"
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With