Code on Github

Bienvenue 환영합니다 Bienvenido - ようこそ Welcome 歡迎光臨

friendly_traceback and friendly help users understand what caused a given exception in their Python program, and how to fix it.


friendly is a program that uses friendly_traceback. From now on, I will generally use friendly to refer to both. I will explain the difference between the two in a separate section. As a user, you almost certainly only need to install and use friendly.

If you need to report a bug, you almost certainly need to report it to friendly_traceback; there is a very simple way to do this from the interactive console: www('bug'), as I will explain later.

There exists many Python projects whose primary goal is to supplement the information given by Python traceback to make them more useful for advanced programmers. To my knowledge, of all those projects, friendly/friendly_traceback are the only ones designed with beginners in mind.

To be more specific, while friendly can be useful for advanced programmers, it strives to present the information in a way that is easily understood by beginners and/or by users who would like to get information about traceback in their own language. friendly can give more detailed information as to where an exception occurred, what a given exception means and why it might have occurred (sometimes adding suggestions as to how to fix it.)

Even though friendly can be used on its own with a specially designed console, a better option might be to use it together with GUI-based editors/IDE including JupyterLab and Jupyter notebooks. I explain how to do so later. For now, I’ll just show one quick example.

A quick look

Consider the following program:

def get_last(seq):
    last_index = len(seq)
    return seq[last_index]

print(get_last([1, 2, 3]))

First, here is what happens when I use Python to run this program.

Python IndexError example

Not exactly the most helpful information for beginners …

Here’s the corresponding version with full explanation from friendly, making use of Rich to produce a colourful output.

friendly IndexError example in English

One unique feature of friendly is that all the information it provides can be translated into another language; currently, only English (by default) and French are available but other languages could easily be added.

friendly IndexError in French

Keep reading if you want to find out more.