How to colorize the output of Python errors in the Gnome terminal?

前端 未结 4 1472
难免孤独
难免孤独 2021-02-09 19:17

Note: I am asking this question after researching how to actually do it. Other questions which are somewhat similar, but actually differ from my question relate to:

    <
4条回答
  •  半阙折子戏
    2021-02-09 19:50

    You could use the IPython coloring. Just put this at the beginning of your program. Every exception will be then handled by ultratb and be displayed in color and also show the locals() values for the code snippet that made the exception.

    import sys
    from IPython.core import ultratb
    sys.excepthook = ultratb.FormattedTB(mode='Verbose', color_scheme='Linux', call_pdb=False)
    

    This will work even if you invoke your script with the vanilla python interpreter.

提交回复
热议问题