aborting without killing the python interpreter

Robert Kern robert.kern at gmail.com
Sun Feb 19 02:27:12 EST 2006


Russ wrote:
> I wrote a simple little function for exiting with an error message:
> 
> def error ( message ): print_stack(); exit ("\nERROR: " + message +
> "\n")
> 
> It works fine for executing as a script, but when I run it
> interactively in the python interpreter it kills the interpreter.
> That's not what I want. Is there a simple way to have a script
> terminate but not have it kill the python interpreter when I run it
> interactively? I suspect I may need to use exceptions, but I'm hoping
> not to need them. Thanks.

Exceptions do *exactly* what you want in a very clean and simple way. They are a
fundamental feature of Python. Do not fear them. They are your friends.

-- 
Robert Kern
robert.kern at gmail.com

"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter




More information about the Python-list mailing list