Autograding Python with understandable error messages using the friendly library
Guides
December 9, 2021

Friendly: Better error messages for Python

Friendly was recently brought to our attention and we knew immediately that we wanted to share this with our teachers. Friendly is an external module for Python that elaborates on what has caused an exception to be thrown in your Python program. To illustrate how Friendly works, they’ve handily provided a great example in their documentation. Say I’ve got this code:

-!- CODE language-py -!-# example.py
def get_last(seq):
    last_index = len(seq)
    return seq[last_index]

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

Running this program with vanilla python in CodeGrade, we get this error traceback:

Regular Python traceback.

While an experienced python programmer knows immediately where to look in the traceback and understands what an IndexError entails, a novice python programmer may not find this information very helpful if they don’t know how indexing works (or what indexing even is).

With Friendly, the error-traceback looks like this:

Student-friendly Python traceback.


Use CodeGrade, the most student friendly autograder available!

At first, the traceback is the same, but Friendly then begins to elaborate what Python’s built-in traceback call is saying. It explains zero-indexing in Python, explains what an IndexError means, and then shows us the specific mistake in the program that caused the error. Friendly even goes on to show the student stored values such as `last_index` which can help the student to have even more oversight on the issues causing their code to fail. It’s also worth noting that Friendly’s traceback can be translated to French and Italian as well (with more languages coming)!

We can use Friendly in CodeGrade really easily as we’ve created a wrapper, `cg-friendly`, which comes pre-installed in the AutoTest virtual Machine. That means no manual installation is necessary! `cg-friendly` acts as if you were running the command `python3 -m friendly example.py` but it makes sure to preserve the exit code of the python program. All that’s required is to run our student’s python program with `cg-friendly example.py` and friendly will be the default traceback method.

Many teachers using CodeGrade, particularly those doing introductory programming courses in python, can certainly benefit from this simple and easy to use tool. As I discussed in my previous blog post about formative feedback, which you can read here, the more context and specificity that is provided in feedback, the better students are able to learn from mistakes and improve their understanding of the programming language. Paired with the iterative coding process that CodeGrade enables, students will learn quicker and better with the help of Friendly’s traceback tool.

Continue reading

Best Practices for Rubric Design in Coding Assignments

Discover best practices for rubric design in coding education. Learn to align rubrics with learning objectives, use automated tests, and explore ungrading for fairer, growth-focused assessments

Watch now! How to teach Python

Watch our 2024 webinar for updates on the Introductory Python course, including new modules, knowledge checks, and grading automation with CodeGrade.

Follow A New User!

See how CodeGrade streamlines grading and improves assignment design in programming courses.

How to configure an AI Assistant for code

CodeGrade’s AI Assistant offers a flexible way to support coding education through tailored guidance and feedback. This guide explains how to configure and customize the assistant to fit your teaching goals, from helping students debug code to providing conceptual explanations.

Sign up to our newsletter

Transform your Jupyter Notebooks course today!