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.

Samuel Natarajan

Samuel Natarajan

Teacher Success Manager
Meet Sam, a music enthusiast! He meticulously ensures CodeGrade clients excel and deeply understand the product, creating an unforgettable experience. He sees CodeGrade's cultural diversity and vibrancy as more than just a workplace.

Continue reading

Get your programming assignments ready for the upcoming academic year!

Prepare your programming course for the new academic year with our comprehensive guide on designing effective assessments and integrating autograding. Enhance student engagement and optimize learning outcomes with practical tips for assignments, projects, and exams.

Course Spotlight: how to set up an Introduction to Python course

Learn how Edward Hartono designs an effective introductory Python programming course for business applications at the University of Delaware

CodeGrade at InstructureCon 2024!

CodeGrade at InstructureCon 2024!

CodeGrade at InstructureCon 2024!

CodeGrade at Anthology Together 2024!

Join CodeGrade at Anthology Together 2024 in Orlando from July 15th to 17th at Booth 304. Discover innovative educational tools like dynamic quizzes, instant feedback, and advanced plagiarism detection

CodeGrade at Anthology Together 2024!

Sign up to our newsletter

See how CodeGrade can transform your courses today!