Is there a way to make python become interactive in the middle of a script?
问题 I'd like to do something like: do lots of stuff to prepare a good environement become_interactive #wait for Ctrl-D automatically clean up Is it possible with python?If not, do you see another way of doing the same thing? 回答1: With IPython v1.0, you can simply use from IPython import embed embed() with more options shown in the docs. 回答2: Use the -i flag when you start Python and set an atexit handler to run when cleaning up. File script.py: import atexit def cleanup(): print "Goodbye" atexit