import sys

def excepthook(type_, value, tb):
    import traceback
import pdb
traceback.print_exception(type_, value, tb)
pdb.post_mortem(tb)
sys.excepthook = excepthook

def main():
    message = 'hello world'
message[20]
main()
How to inspect variables after Traceback?