aborting without killing the python interpreter
Terry Reedy
tjreedy at udel.edu
Sun Feb 19 00:33:31 EST 2006
"Russ" <uymqlp502 at sneakemail.com> wrote in message
news:1140320926.993703.90380 at o13g2000cwo.googlegroups.com...
>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,
How? In the standard interpreter, 'exit' is bound to the string
'Use Ctrl-Z plus Return to exit.'
so trying to call it as a function fails.
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.
The interactive interpreter runs a statement at a time and gives a prompt
after any output. From a command shell, you can use a flag (-i I think) to
enter interactive mode after the script end.
Terry Jan Reedy
More information about the Python-list
mailing list