I am using Python 2.7. When I try to print a simple string to a file, I get the following error:
Syntax error: invalid tuple
Syntax error while detecting tuple
minimal example:
fly = open('workfile', 'w')
print('a', file=fly)
writing to the same file via fly.write('a')
works just fine.
You are using the Python 3 syntax in Python 2.
In Python 2, it's like this:
print >> fly, 'a'
However, a better idea is to do this:
from __future__ import print_function
Which will enable the Python 3 syntax if you are using Python 2.6 or 2.7.
See also: http://docs.python.org/2/library/functions.html#print
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With