[Python-ideas] Special-case 3.x 'print x' SyntaxError

Chris Angelico rosuav at gmail.com
Mon Sep 15 10:23:59 CEST 2014


On Mon, Sep 15, 2014 at 6:12 PM, Terry Reedy <tjreedy at udel.edu> wrote:
> 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(...)"?

You mean like this?

rosuav at dewey:~$ python3
Python 3.4.1+ (default, Aug 18 2014, 12:06:51)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print "Hello?"
  File "<stdin>", line 1
    print "Hello?"
                 ^
SyntaxError: Missing parentheses in call to 'print'

ChrisA


More information about the Python-ideas mailing list