Skip to main content

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

Example


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
)

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.)


Configuration settings:
  • line_length
    Output will be wrapped at this point. If set to 0 (which is the default) it will automatically match your console width.

  • full_line_newline
    Insert a hard newline even if the line is full. If line_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 be pretty_errors.FILENAME_COMPACT, pretty_errors.FILENAME_EXTENDED, or pretty_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. When 0 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pretty_errors-1.1.1.tar.gz (5.0 kB view hashes)

Uploaded Source

Built Distribution

pretty_errors-1.1.1-py3-none-any.whl (5.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page