我在以下语句中随机收到 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)