Syntax error for simple script

Steve D'Aprano steve+python at pearwood.info
Tue Jun 27 10:05:35 EDT 2017


On Tue, 27 Jun 2017 08:34 am, Erik wrote about the print function error message:

py> print x
  File "<stdin>", line 1
    print x
          ^
SyntaxError: Missing parentheses in call to 'print'


> To be fair, this already seems to be a special case:
[...]
>  >>> len "bar"
>    File "<stdin>", line 1
>      len "bar"
>              ^
> SyntaxError: invalid syntax

Correct, the print function is singled out as a special case, because people are
unlikely to come across tutorials telling them to write

   len "bar"


> If that's the case, then why make it so terse? It's presumably there as
> a special case specifically to tell/remind people that print became a
> function in Py3.

Indeed. But it is hardly terse: it's a full sentence:

Missing parentheses in call to 'print'

(although missing the full stop at the end, if anyone cares enough to raise a
bug report for that).


> I think the suggestion above is a bit wordy, but even if it was
> something like "Missing parentheses in call to the 'print' function"

I think this is a good example of "the curse of knowledge". Its hard for experts
to think like a non-expert.

It seems obvious to us that adding the word "function" will make it clear to the
user what's going on. We understand that print is now a function, and function
calls always need parentheses, but that print used to be a statement like
while, for, if, etc. that doesn't need parentheses.

To a moderately experienced programmer, the word "function" doesn't actually add
anything, but it isn't harmful: the error is just a reminder of what they
probably already know.

But to the beginner, adding "function" at the error might as well be 

Missing parentheses in call to the 'print' wharrgarbl.


It's just jargon. They can either diagnose the problem from the first part of
the sentence telling them that there are missing parentheses, or they can't. If
they can't, I doubt that adding the word "function" (or any other jargon term
like subroutine, procedure or callable) will help.

Anyway, that's my opinion. If any newbies, like the OP, would like to venture an
opinion, that would be good. That's why I asked Ben if there was something we
could do to make the sentence clearer.



> or 
> even "Missing parentheses in call to 'print'. Using 'print' as a
> statement is obsolete syntax in Python 3." ... or whatever is considered
> more descriptive.

When it comes to error messages, more is not always better. There is a balance
needed between too terse and too verbose and wordy.

Users don't read error messages, even when they are well-written:

https://ux.stackexchange.com/questions/393/how-do-i-get-users-to-read-error-messages

https://stackoverflow.com/questions/2356698/how-to-get-users-to-read-error-messages

so adding more words is not necessarily going to help beginners. In fact it
might even make it *less* likely that they read the error. Reading error
messages is a skill that needs to be learned, or taught.


> Either that or just make it "SyntaxError: invalid syntax" like all the
> others.

We've been there: adding the specific print message is new to Python 3.5 (or
maybe 3.4, I forget which). Python 3.3 gives just "SyntaxError: invalid
syntax".



-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.




More information about the Python-list mailing list