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

How to automatically grade R assignments

Streamline R Assignments with Automatic Grading in CodeGrade

Watch now! Efficient Grading with AutoTestV2!

Discover how AutoTest V2's streamlined grading and instant feedback transform the grading process for educators.

You're invited! Join our AI Assistant webinar

Discover CodeGrade’s AI Code Assistant! Join our webinar on Nov 20 with Professor Brian Brady to explore AI’s role in authentic code learning and skill-building.

How to automatically grade SQL assignments

Learn how to set up SQL assignments with CodeGrade for efficient assessment and feedback.

Sign up to our newsletter

See how CodeGrade can transform your courses today!