Last active
February 8, 2018 22:33
-
-
Save gwparikh/797559acf7d0164cfd32 to your computer and use it in GitHub Desktop.
Python - Start interactive shell on exception
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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