pythoncommand-lineexceptioninteractive-mode

Handling exceptions without try block in Python's interactive shell


See the title of this question. I want to play with the exception raised in the last command. _ didn't help me. Is there anything like that?


Solution

  • Do this:

    import sys
    sys.exc_info()
    

    It will give you information about the exception. It's a tuple containing the exception type, the exception instance and a traceback object.