Python: how to control namespace after an unhandled exception?
问题 Is there any way to control which namespace you end up in after an unhandled exception? For example, if I'm at an ipython prompt and I go run blah.py on a file with these contents: def spam(): ham = 'ham' crash = 1/0 eggs = 'eggs' if __name__ == '__main__': foo = 'foo' spam() it crashes out obviously but returns me to an ipython prompt, with foo now in the namespace (and any previously existing foo is now overwritten with 'foo' ). But no ham . For some post mortem inspection, it is often the