2016-11-14 48 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: 
相關問題