How to get the last exception object after an error is raised at a Python prompt?
问题 When debugging Python code at the interactive prompt (REPL), often I'll write some code which raises an exception, but I haven't wrapped it in a try / except , so once the error is raised, I've forever lost the exception object. Often the traceback and error message Python prints out isn't enough. For example, when fetching a URL, the server might return a 40x error, and you need the content of the response via error.read() ... but you haven't got the error object anymore. For example: >>>