Prettifies Python exception output to make it legible.
Project description
pretty-errors
Prettifies Python exception output to make it legible. Install it with
python -m pip install pretty-errors
Use it simply by importing it:
import pretty_errors
Note you need to be running in a terminal capable of colour output in order to get colour output: in Windows this means powershell, cmder, etc.
If you want to configure the output then use pretty_errors.configure()
. For example:
import pretty_errors
pretty_errors.configure(
seperator_character = '*',
filename_display = pretty_errors.FILENAME_FULL,
lines_before = 2,
lines_after = 1
)
pretty_errors.blacklist('c:/python')
It is possible to have the interactive interpreter always use pretty_errors
, instead of including it in your projects, by using the PYTHONSTARTUP
environment variable. Set it to a python file and that file will be run every time python is. If you don't already have one then create a file with the above code block and set PYTHONSTARTUP
to its path. Whenever you run python interactively, pretty_errors
will be automatically imported and configured (though this will not be true when your python code is run outwith the interactive interpreter.)
Whitelist / Blacklist:
You may use the functions whitelist(path)
and blacklist(path)
to add paths which will be necessary (whitelist
) or excluded (blacklist
). The top frame of the stack is never excluded.
Configuration settings:
-
line_length
Output will be wrapped at this point. If set to0
(which is the default) it will automatically match your console width. -
full_line_newline
Insert a hard newline even if the line is full. Ifline_length
is the same as your console width and this is enabled then you will see double newlines where unwanted, so usually you would only set this if they are different. -
filename_display
How the filename is displayed: may bepretty_errors.FILENAME_COMPACT
,pretty_errors.FILENAME_EXTENDED
, orpretty_errors.FILENAME_FULL
-
display_timestamp
When enabled a timestamp is written in the traceback header. -
display_link
When enabled a link is written below the error location, which VSCode will allow you to click on. -
exception_above
When enabled the exception is displayed above the stack trace. -
exception_below
When enabled the exception is displayed below the stack trace. -
line_number_first
When enabled the line number will be displayed first, rather than the filename. -
top_first
When enabled the stack trace will be reversed, displaying the top of the stack first. -
stack_depth
The maximum number of entries from the stack trace to display. When0
will display the entire stack, which is the default. -
lines_before
,lines_after
How many lines of code to display for the top frame, before and after the line the exception occurred on. -
trace_lines_before
,trace_lines_after
How many lines of code to display for each other frame in the stack trace, before and after the line the exception occurred on. -
seperator_character
Character used to create the header line. Hyphen is used by default. -
prefix
Text string which is displayed at the top of the report, just below the header. -
infix
Text string which is displayed between each frame of the stack. -
postfix
Text string which is displayed at the bottom of the exception report. -
header_color
Escape sequence to set header color. -
timestamp_color
Escape sequence to set timestamp color. -
line_color
Escape sequence to set the color of the line of code which caused the exception. -
code_color
Escape sequence to set the color of other displayed lines of code. -
filename_color
Escape sequence to set filename color. -
line_number_color
Escape sequence to set line number color. -
function_color
Escape sequence to set function color. -
exception_color
Escape sequence to set exception color. -
exception_arg_color
Escape sequence to set exception arguments color. -
link_color
Escape sequence to set link color. -
reset_stdout
When enabled the reset escape sequence will be written to stdout as well as stderr; turn this on if your console is being left with the wrong color.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for pretty_errors-1.1.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce2415a570ffb667d7e897a8b9cbce62eb7ec72e61f5283e253fac82d1d57168 |
|
MD5 | 0c34bffb70bf6f3485228dc46b0afed3 |
|
BLAKE2b-256 | 13fae711c94b009c4502380b970245d01fa61f82ecde92bc6f6260f478b79dc2 |