From 5191c9b66618b86a3fe83ebee83b1368572b5f65 Mon Sep 17 00:00:00 2001 From: blag Date: Sat, 15 Apr 2017 04:56:06 -0600 Subject: [PATCH] Add IPython instructions to README.md --- README.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/README.md b/README.md index b9b8df3..8c77cf1 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,41 @@ import better_exceptions That's it! +### IPython + +If you are using IPython, you will need to register a startup hook for better_exceptions. + +Add this code to `$HOME/.ipython/profile_default/startup/00-better_exceptions.py`: + +```python +from __future__ import print_function +import better_exceptions, sys + +ip = get_ipython() +old_show = ip.showtraceback + +def exception_thunk(exc_tuple=None, filename=None, + tb_offset=None, exception_only=False): + print("Thunk: %r %r %r %r" % (exc_tuple, filename, tb_offset, exception_only), + file=sys.stderr) + notuple = False + if exc_tuple is None: + notuple = True + exc_tuple = sys.exc_info() + use_better = True + use_better = use_better and (filename is None) + use_better = use_better and (tb_offset is None) + use_better = use_better and (not exception_only) + use_better = use_better and (not isinstance(exc_tuple[0], SyntaxError)) + if use_better: + return better_exceptions.excepthook(*exc_tuple) + else: + return old_show(None if notuple else exc_tuple, + filename, tb_offset, exception_only) + +ip.showtraceback = exception_thunk +``` + ### Advanced Usage If you want to allow the entirety of values to be outputted instead of being truncated to a certain amount of characters: