Reputation: 159331
I want to stop a Python script on seeing an error message.
I dont want any error message on shell like exit().
How to do it ???
Upvotes: 0
Views: 11518
Reputation: 3323
When you send CTRL+C to a Python script, it raises the KeyboardInterrupt
exception, so you can do something like
try:
... Work goes here ...
except KeyboardInterrupt:
sys.exit(0)
Upvotes: 9