Syntax error for simple script
Erik
python at lucidity.plus.com
Mon Jun 26 18:34:06 EDT 2017
On 26/06/17 18:30, Chris Angelico wrote:
> On Tue, Jun 27, 2017 at 2:41 AM, Rurpy via Python-list
> <python-list at python.org> wrote:
>> How about:
>>
>> In Python 2, 'print' was a statement and did not require
>> parenthesis around its argument. In Python 3 'print' has
>> been changed to a function and now, like all functions,
>> requires parenthesis around its arguments:
>> python 2: print arg1, arg2,...
>> python 3: print (arg1, arg2,...)
>
> Absolutely, if we consider that Python 2 is the official standard and
> Python 3 is a buggy interloper. But if Python 3 is the standard and
> Python 2 is the legacy version, then the existing message is far more
> appropriate, without being unhelpful.
To be fair, this already seems to be a special case:
-----------------------------------------------------------
$ python3
Python 3.5.2 (default, Nov 17 2016, 17:05:23)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> def foo(s): return s
...
>>> type(foo)
<class 'function'>
>>> type(enumerate)
<class 'type'>
>>> type(len)
<class 'builtin_function_or_method'>
>>> type(print)
<class 'builtin_function_or_method'>
>>> foo "bar"
File "<stdin>", line 1
foo "bar"
^
SyntaxError: invalid syntax
>>> enumerate "bar"
File "<stdin>", line 1
enumerate "bar"
^
SyntaxError: invalid syntax
>>> len "bar"
File "<stdin>", line 1
len "bar"
^
SyntaxError: invalid syntax
>>> print "bar"
File "<stdin>", line 1
print "bar"
^
SyntaxError: Missing parentheses in call to 'print'
>>> p = print
>>> p "foo"
File "<stdin>", line 1
p "foo"
^
SyntaxError: invalid syntax
>>>
-----------------------------------------------------------
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.
I think the suggestion above is a bit wordy, but even if it was
something like "Missing parentheses in call to the 'print' function" 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.
Either that or just make it "SyntaxError: invalid syntax" like all the
others. It seems to fall somewhere between the two at the moment - it's
trying to be more helpful but just falls short for a beginner (if one
already knows the difference and has just forgotten to call it
correctly, it's a nice *reminder*, so I'd actually prefer it not to just
become the basic "invalid syntax" message).
E.
More information about the Python-list
mailing list