Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add IPython instructions to README.md #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be removed.

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:
Expand Down