Python 2.7 を使用しています。単純な文字列をファイルに出力しようとすると、次のエラーが発生します。
構文エラー: タプルが無効です
タプル検出時の構文エラー
最小限の例:
fly = open('workfile', 'w')
print('a', file=fly)
経由で同じファイルに書き込むことはfly.write('a')
問題なく機能します。
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
ドキュメントを確認する
注意 名前 print は print ステートメントとして認識されるため、通常、この関数は組み込みとして使用できません。ステートメントを無効にして print() 関数を使用するには、モジュールの先頭で次の future ステートメントを使用します。 from future import print_function