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

Friendly: Better error messages for Python

In 30 seconds...

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
Samuel is Teacher Success Manager at CodeGrade and works hand-in-hand with Teachers and Professors in CS education. He’s trained in Cognitive Neuroscience but has a broad view on education, software development, and tech that sees him fit in comfortably with the IT crowd. In his free time he boulders, throws frisbees for fun and makes a mean stir-fry.

Continue reading

Teaching Intro to Python with CodeGrade

The CodeGrade Introduction to Python course is an 8-week basic Python course. Students are not required to have any prior knowledge on programming or Python. This course will cover the basic concepts of programming up to Python specific modules and OOP design. It is available for all instructors now.

New release CodeGrade QuietStorm.1!

Find out about all the features and updates coming with our latest release, QuietStorm.1!

New release CodeGrade QuietStorm.1!

Automatically grading Haskell code assignments

Learn about autograding Haskell coding assignments for Computer Science education courses. CodeGrade can help you use tools like input and output checking, Quickcheck, Tasty and HUnit unit test autograding, HLint code quality checking and code structure autograding using semgrep.

Top tips for teaching programming

The most efficient ways to teach students how to code, by defining your target audience, designing your assignments in a meaningful way and eliminating distractions in the classroom.

Top tips for teaching programming

Learn more about CodeGrade!

Grow your coding classroom
without compromise.