mirror of https://github.com/Textualize/rich.git
traceback doc update
This commit is contained in:
parent
774c7c224d
commit
c41b654d75
|
@ -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 <https://github.com/willmcgugan/rich/blob/master/examples/exception.py>`_ for a larger example.
|
||||
|
||||
|
||||
Traceback handler
|
||||
-----------------
|
||||
|
|
Loading…
Reference in New Issue