[Python-ideas] Special-case 3.x 'print x' SyntaxError
Terry Reedy
tjreedy at udel.edu
Mon Sep 15 10:12:31 CEST 2014
One of the problems with new Python programmers using 3.x is that they
first read 'print x' in 2.x based material, try 'print x' in 3.x, get
"SyntaxError: invalid syntax" (note the uninformative redundant
message), and go "huh?" or worse.
Would it be possible to add detect this particular error and print a
more useful message? I am thinking of something of something like
SyntaxError: calling the 'print' function requires ()s, as in "print(x)"
or maybe
SyntaxError: did you mean "print(...)"?
I was 'inspired' by a recent SO question
https://stackoverflow.com/questions/24273599/idle-gui-is-unable-to-give-output
which was closed as a duplicate of the 2009 question
https://stackoverflow.com/questions/826948/syntax-error-on-print-with-python-3
I imagine that there have been other duplicates. The same question (and
answer) has appeared multiple times on python-list also.
If we do this, I am sure someone will ask why we do not automatically
'fix' the error. One answer would be that the closing ) is needed to
determine the intended end of the call. A longer version would be that
if we insert (, we are just guessing that the insertion is correct and
we still would not know, without guessing, where to put the ).
--
Terry Jan Reedy
More information about the Python-ideas
mailing list