以下のステートメントでランダムに、Python のコンパイラによって「SyntaxError」例外が発生します。
with open(inputFileName, 'rU') as inputFile, open(outputFileName,'w') as outputFile:
^
SyntaxError: invalid syntax
ここでinputFileNameは私のビルド環境からのコマンドラインパラメータであり、スクリプトが呼び出される前に作成されて存在することが期待されています. 以下はサンプルコードです。
try:
with open(inputFileName, 'rU') as inputFile, open(outputFileName,'w') as outputFile:
print "do something"
except IOError as e: #(errno,strerror,filename):
## Control jumps directly to here if any of the above lines throws IOError.
sys.stderr.write('problem with \'' + e.filename +'\'.')
sys.stderr.write(' I/O error({0}): {1}'.format(e.errno, e.strerror) + '.' + '\n')
except:
print "Unexpected error in generate_include_file() : ", sys.exc_info()[0]
手がかりがありません。私を助けてください。私はpython 2.7を使用しています。(python27)