A simple print cannot run in Python Shell
Jussi Piitulainen
jpiitula at ling.helsinki.fi
Mon Jun 1 03:59:29 EDT 2015
fl writes:
> When I run the following command in a Python 2.7.9 Shell on Windows 7,
>
> print r'C:\\nowhere'
>
> It has error:
>
>>>> print r'C:\\nowhere'
> SyntaxError: invalid syntax
>
> What is the problem? Why does it behave different at .py file
> and Python Shell?
Have you executed the following in that shell?
from __future__ import print_function
That replaces the Python 2 print command with the Python 3 print
function and then you would get that error message.
Apologies if you've done that because I used it in one of my examples
about reversed(). I didn't mean to confuse - I've just never quite
learnt the Python 2 print syntax myself.
There is no "from __past__ import print_command", is there? To recover
the original functionality in that shell :)
More information about the Python-list
mailing list