Skip to content

Instantly share code, notes, and snippets.

@gwparikh
Last active February 8, 2018 22:33
Show Gist options
  • Save gwparikh/797559acf7d0164cfd32 to your computer and use it in GitHub Desktop.
Save gwparikh/797559acf7d0164cfd32 to your computer and use it in GitHub Desktop.
Python - Start interactive shell on exception
#!/usr/bin/python
import sys
import os, traceback
try:
pass # put code that may fail here
except:
print traceback.format_exc() # print the exception
os.environ['PYTHONINSPECT'] = 'Y' # start interactive/inspect mode (like using the -i option)
if 'PYTHONSTARTUP' in os.environ:
pyrc = os.environ['PYTHONSTARTUP']
if os.path.exists(pyrc):
execfile(pyrc) # run the user's pythonstartup file if it exists
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment