我从一端使用带有Python 2.7.12的Windows 7,另一端使用带有Python 2.6.6的Red Hat Enterprise Linux Server 6.5版。
我的脚本在Windows上运行正常但在RHEL上运行不正常。
我收到以下语法错误:
with open('pathtofile', 'rb') as f_input, open('pathtofile', 'w') as f_output:
# ^
SyntaxError: invalid syntax
这可能是由两个系统上不同版本的Python引起的?
答案 0 :(得分:3)
with open('pathtofile', 'rb') as f_input, open('pathtofile', 'w') as f_output:
Python 2.6不支持。在该版本中,您只能在with
语句中打开一个文件。相反,你可以做
with open('pathtofile', 'rb') as f_input:
with open('pathtofile', 'w') as f_output: