Autograding Python with understandable error messages using the friendly library
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 -!-#
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` 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` 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

Coding Quizzes are here!

Discover the latest addition to CodeGrade: coding quizzes! Elevate your learning experience with dynamic assessments seamlessly integrated with AutoTest V2. Engaging, clear, and user-friendly. Learn more now!

Coding Quizzes are here!

Transforming CS Education: Innovative Strategies for Curriculum Enhancement

Discover how Experiential Learning Theory transforms traditional teaching methods and improves computer science curriculum for optimal student engagement and success.

CodeGrade Announces Partnership with Pearson to Transform Coding Education

Today, CodeGrade announced a partnership with Pearson to deliver an enhanced technology for educators to better serve students.

Why Data Security Matters in Academia: Safeguarding Your Digital Assets

We discuss protecting sensitive data in higher education: safeguarding student confidentiality, research integrity, and fostering trust.

Sign up to our newsletter

Schedule a personalized tour of CodeGrade today