I think your problem is that you are on Python 2.x and using Python 3.x syntax. In Python 3.x, print is built-in and can be used like this. However, in 2.x it is a keyword and cannot. If you are on 2.x, do the following:
print data.readline(),
One way to see which version of Python you are using:
import sys if sys.version_info.major == 2:
or, from the terminal:
$ python --version
The best way to fix this problem is probably to upgrade to Python 3.x. However, if you cannot, you can look at the __future__ module. This can make it so that you can use the Python 3.x print function in 2.x:
>>> from __future__ import print_function >>> print("yes!") yes! >>> print("a", "b", sep=",") a,b >>>
source share