2016-11-14 47 views
1

我从一方使用Python 2.7.12,另一方使用Python 2.6.6的红帽企业Linux服务器版本6.5。为什么Python脚本可以在Windows上运行,而不是在Linux上运行?

我有一个脚本,可以在Windows上正常工作,但不在RHEL上。

我收到以下语法错误:

with open('pathtofile', 'rb') as f_input, open('pathtofile', 'w') as f_output: 
#          ^ 

SyntaxError: invalid syntax 

它可以通过在两个系统不同版本的Python造成的?

回答

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: 
相关问题