5

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

 2 years ago
source link: https://friendly-traceback.github.io/docs/index.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

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:

# example.py
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.

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.

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.

Keep reading if you want to find out more.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK