I've always wondered how to do this, it's useful for manual unit testing of individual python scrips. Say I had a python file that did something, and I wanted to run it in the top level, but after it finishes, I want to pick up where it leaves off. I want to be able to use the objects it creates, etc.
A simple example, let's say I have a python script that does i = 5. When the script ends, I want to be returned to the top level and be able to continue with i = 5.