Python console rejects an object reference, having made an object with that reference as its name in previous line

Chris Angelico rosuav at gmail.com
Mon Dec 15 00:32:22 EST 2014


On Mon, Dec 15, 2014 at 4:27 PM, Michael Torrie <torriem at gmail.com> wrote:
> On 12/14/2014 07:47 PM, Mark Lawrence wrote:
>> I didn't realise that Python was so smart.  It can indicate a syntax
>> error at the final 't' in print before it gets to the opening bracket
>> that is required for the print function in Python 3 (and Python 2 if
>> you're using "from __future__ import print_function")?
>
> Not really.  Python2 just interprets "print (value)" as an expression to
> the print statement.  It's like saying "a=(value)" and then "print a".
> Redundant but works.  However "print(value)" is interpreted as a
> function call, and if you haven't imported it from future, it will error
> out on Python2.

Did you actually test that?

Python 2.7.8 (default, Jun 30 2014, 16:03:49) [MSC v.1500 32 bit
(Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> print("hello")
hello

Since print is a keyword when not imported from future, there's no way
for print(value) to be parsed as a function call.

ChrisA



More information about the Python-list mailing list