[IPython-user] EOF for the cmd class
justin at mac.com
Thu Nov 25 13:34:49 CST 2004
Thanks for taking a look at this. More below.
On Nov 24, 2004, at 23:13, Fernando Perez wrote:
> Justin Walker wrote:
>> If I run this code and type ^D in python, the interpreter exits to
>> shell. If I do the same with ipython, it complains, with a
>> traceback, and the comment that that I should use ^D to exit (:-}).
> Ipython is behaving as intended in this case: when you type 'run
> rolo', ipython will execute your python script, but it will trap all
> SystemExit calls to avoid user code blowing up ipython itself.
I begin to see what's going on. This is an "exit python" hook, not an
exit the command-loop hook.
> Having clarified that, let me make a suggestion: don't use sys.exit()
> to abort execution as a normal mechanism
I've now figured that out. FWIW, my (1st edition) Learning Python book
gives this (sys.exit) as the way to exit from the command loop, and I
was just faithfully following, sheep-like.
> If you simply let your 'main' function return cleanly at the end of
> the script, python will close the execution loop, and ipython won't
> give you the nasty warnings which are now bothering you. You should
> consider sys.exit() as an emergency bailout, not as the normal
> termination mechanism.
Haven't figured out how to exit the command loop yet. It appears that
'return' from any of the 'do_' hooks will just go back into the command
loop, and I have yet to find documentation that describes how to deal
with this. Time to UTSL: OK, return 'True'. I guess I missed that in
the doc :-}
> I hope this helps.
Yes it does; thanks!
/~\ The ASCII Justin C. Walker, Curmudgeon-at-Large
\ / Ribbon Campaign
X Help cure HTML Email
More information about the IPython-user