I've been working with iPython notebooks for a while and I really appreciated how the error output (if I made a spelling/syntax error) was in color like this:
However, when I run code from the terminal (because ipython cannot do everything yet), I don't get any color, like so:
Of course that might vary by terminal/operating system, but I was curious if there are any easy package/plugin to make python error output in the terminal to be in color please? or even what to look for (I run zsh on ubuntu).
Digging through the IPython API reference turns up IPython.core.ultratb
, the module IPython itself uses for colorful exception formatting. You should be able to do
try:
import IPython.core.ultratb
except ImportError:
# No IPython. Use default exception printing.
pass
else:
import sys
sys.excepthook = IPython.core.ultratb.ColorTB()
to check whether IPython is available, and if so, use its exception printer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With