stop script w/o exiting interpreter
Alan Isaac
aisaac at american.edu
Sat Jan 27 18:07:08 EST 2007
Please note that this post has subject
"stop script w/o exiting interpreter".
The object is to work at the *interactive* interpreter,
without leaving it.
Here is an example goal:
start a Python shell,
execfile a script,
exit the script at line 25,
and return to the Python shell.
E.g., some languages include a ``stop`` statement that you can put on line
25.
Ideally, I would like the equivalent of this.
Solutions suggested in this thread included:
- raise SystemExit
but this will exit the interpreter
- sys.exit()
but this will exit the interpreter
- use pdb's set_trace()
but I think that answers a different question.
(However it does work to raise BdbQuit, but I'd like something less
messy.)
- wrap all code in functions and test the functions
but this does not apply to my current use case
- use PyScripter
but this is overkill for my very simple goal
Note that I can just put the undefined name ``stop`` on any line
I want, and the script will stop execucting at that line and will
return to the interactive interpreter, as I wish. It is just that it
returns with an error message, and I'd like to avoid that.
Thanks,
Alan Isaac
More information about the Python-list
mailing list