From c41b654d7561e1fbf0154fc6cadb911b4455f5a0 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Tue, 3 Aug 2021 17:27:42 +0100 Subject: [PATCH] traceback doc update --- docs/source/traceback.rst | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/docs/source/traceback.rst b/docs/source/traceback.rst index 60eee13f..ee0d64be 100644 --- a/docs/source/traceback.rst +++ b/docs/source/traceback.rst @@ -1,7 +1,11 @@ Traceback ========= -Rich can render Python tracebacks with syntax highlighting and formatting. Rich tracebacks are easier to read, and show more code, than standard Python tracebacks. +Rich can render Python tracebacks with syntax highlighting and formatting. Rich tracebacks are easier to read and show more code than standard Python tracebacks. + +To see an example of a Rich traceback, running the following command:: + + python -m rich.traceback Printing tracebacks @@ -9,14 +13,18 @@ Printing tracebacks The :meth:`~rich.console.Console.print_exception` method will print a traceback for the current exception being handled. Here's an example:: - import rich + from rich.console import Console + console = Console() + try: do_something() - except: - console = rich.console.Console() + except Exception: console.print_exception(show_locals=True) -The ``show_locals=True`` parameter causes Rich to display the value of local variables for each section of the traceback. +The ``show_locals=True`` parameter causes Rich to display the value of local variables for each frame of the traceback. + +See `exception.py `_ for a larger example. + Traceback handler -----------------