Skip to content

Instantly share code, notes, and snippets.

@vindolin
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vindolin/b451626ebd331cff23fd to your computer and use it in GitHub Desktop.
Save vindolin/b451626ebd331cff23fd to your computer and use it in GitHub Desktop.
# from http://stackoverflow.com/a/14776693/999193
import sys
def myexcepthook(type, value, tb):
import traceback
from pygments import highlight
from pygments.lexers import get_lexer_by_name
from pygments.formatters import TerminalFormatter
tbtext = ''.join(traceback.format_exception(type, value, tb))
lexer = get_lexer_by_name("pytb", stripall=True)
formatter = TerminalFormatter()
sys.stderr.write(highlight(tbtext, lexer, formatter))
sys.excepthook = myexcepthook
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment