I have a fix for this using a Python template, which is to use Python raw strings for the student_answer and the __tester__.java classes, and not use e('py') at all. I haven't worked out how to do it using the java_class template yet.
So my new template has
student_answer = r"""{{ STUDENT_ANSWER }}"""
and
with open("__tester__.java", "w") as f:
f.write(r"""
public class __tester__ { // etc
This also solves the issue for test cases, which otherwise fail when you use escaped characters. The problem isn't just with \" but also with \\ and \n inside a string.
This approach probably doesn't work if the student uses triple quotes (text blocks) in Java, which has been available in java for a while now.
So my new template has
student_answer = r"""{{ STUDENT_ANSWER }}"""
and
with open("__tester__.java", "w") as f:
f.write(r"""
public class __tester__ { // etc
This also solves the issue for test cases, which otherwise fail when you use escaped characters. The problem isn't just with \" but also with \\ and \n inside a string.
This approach probably doesn't work if the student uses triple quotes (text blocks) in Java, which has been available in java for a while now.