<div dir="ltr"><span id="inbox-inbox-docs-internal-guid-2fb0c0b4-ae70-c883-5d1f-77ecba187548"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;font-family:arial;vertical-align:baseline;white-space:pre-wrap">I teach a computing subject to high school students using Python as our primary language. One thing that often causes confusion at the start is error messages/exceptions. I think it would lower entry point quite a bit by making error messages more readable to novices. Recent research found reduced frequency of overall errors, errors per student, and repeated errors when error messages were enhanced [1].</span></p><div dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><br></div><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;font-family:arial;vertical-align:baseline;white-space:pre-wrap">This could be implemented by a command-line switch when running python, or a different python executable (along the lines of pythonw.exe vs python.exe) such as python-easy. A simpler error message might get rid of excess information which can confuse the novice (such info might be dumped to a file to allow more advanced users to debug), provide a brief description of what the error might mean, and/or how you might fix it. So a SyntaxError might tell the user that they've probably forgotten a :, and a NameError might say that the item has been defined yet, or they've made a typo. A couple of examples follow:</span></p><div dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><br></div><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;font-family:consolas;color:rgb(255,0,0);background-color:transparent;vertical-align:baseline;white-space:pre-wrap">Traceback (most recent call last):</span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;font-family:consolas;color:rgb(255,0,0);background-color:transparent;vertical-align:baseline;white-space:pre-wrap">  File "foo.py", line 2, in <module></span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;font-family:consolas;color:rgb(255,0,0);background-color:transparent;vertical-align:baseline;white-space:pre-wrap">    l[10]=14</span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;font-family:consolas;color:rgb(255,0,0);background-color:transparent;vertical-align:baseline;white-space:pre-wrap">IndexError: list assignment index out of range</span></p><div dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><br></div><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;font-family:arial;background-color:transparent;vertical-align:baseline;white-space:pre-wrap">A better message might be:</span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;margin-left:34.5pt"><span style="font-size:14.6667px;font-family:arial;background-color:transparent;vertical-align:baseline;white-space:pre-wrap">You tried to use l[10] when l is only 4 elements long. You can add items to l using l.append(value), or check your index value to make sure that's really the position you wanted to access. </span></p><div dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><br></div><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;font-family:consolas;color:rgb(255,0,0);background-color:transparent;vertical-align:baseline;white-space:pre-wrap">Traceback (most recent call last):</span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;font-family:consolas;color:rgb(255,0,0);background-color:transparent;vertical-align:baseline;white-space:pre-wrap">  File "foo.py", line 2, in <module></span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;font-family:consolas;color:rgb(255,0,0);background-color:transparent;vertical-align:baseline;white-space:pre-wrap">    while name != "quit" and reponse != "quit":</span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;font-family:consolas;color:rgb(255,0,0);background-color:transparent;vertical-align:baseline;white-space:pre-wrap">NameError: name 'reponse' is not defined</span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;font-family:arial;background-color:transparent;vertical-align:baseline;white-space:pre-wrap">A better message might be:</span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;margin-left:34.5pt"><span style="font-size:14.6667px;font-family:arial;background-color:transparent;vertical-align:baseline;white-space:pre-wrap">You're trying to use the value of 'reponse', but that variable hasn't got a value yet. You can give it a value earlier in the code, or it could be a typo. You have a variable called 'response' - is that the one you meant?</span></p><div dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><br></div><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;font-family:consolas;color:rgb(255,0,0);background-color:transparent;vertical-align:baseline;white-space:pre-wrap">Traceback (most recent call last):</span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;font-family:consolas;color:rgb(255,0,0);background-color:transparent;vertical-align:baseline;white-space:pre-wrap">  File "foo.py", line 2, in <module></span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;font-family:consolas;color:rgb(255,0,0);background-color:transparent;vertical-align:baseline;white-space:pre-wrap">    print(length(l))</span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;font-family:consolas;color:rgb(255,0,0);background-color:transparent;vertical-align:baseline;white-space:pre-wrap">NameError: name 'length' is not defined</span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;font-family:arial;background-color:transparent;vertical-align:baseline;white-space:pre-wrap">A better message might be:</span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;margin-left:34.5pt"><span style="font-size:14.6667px;font-family:arial;background-color:transparent;vertical-align:baseline;white-space:pre-wrap">Python doesn't recognise the function "length". Did you mean len?'</span></p><div dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;margin-left:34.5pt"><br></div><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;font-family:consolas;color:rgb(255,0,0);vertical-align:baseline;white-space:pre-wrap">  File "foo.py", line 2</span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;font-family:consolas;color:rgb(255,0,0);vertical-align:baseline;white-space:pre-wrap">    for i in l</span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;font-family:consolas;color:rgb(255,0,0);vertical-align:baseline;white-space:pre-wrap">             ^</span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;font-family:consolas;color:rgb(255,0,0);vertical-align:baseline;white-space:pre-wrap">SyntaxError: invalid syntax</span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;font-family:arial;background-color:transparent;vertical-align:baseline;white-space:pre-wrap">A better message might be:</span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;margin-left:34.5pt"><span style="font-size:14.6667px;font-family:arial;background-color:transparent;vertical-align:baseline;white-space:pre-wrap">You have a for loop without a : (colon). Try adding a colon at the end of the line.</span></p><div dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><br></div><div dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><br></div><div style="line-height:1.38;margin-top:0pt;margin-bottom:0pt">Any thoughts?</div><div dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;margin-left:34.5pt"><br></div><span style="font-size:14.6667px;font-family:arial;background-color:transparent;vertical-align:baseline;white-space:pre-wrap">[1]: </span><a href="http://researchrepository.ucd.ie/handle/10197/7583" style="text-decoration:none"><span style="font-size:14.6667px;font-family:arial;color:rgb(17,85,204);background-color:transparent;text-decoration:underline;vertical-align:baseline;white-space:pre-wrap">http://researchrepository.ucd.ie/handle/10197/7583</span></a><span style="font-size:14.6667px;font-family:arial;background-color:transparent;vertical-align:baseline;white-space:pre-wrap"> </span></span></div><div dir="ltr">-- <br></div><div data-smartmail="gmail_signature"><div dir="ltr"><p dir="ltr">Victor Rajewski</p>
</div></div>