简体   繁体   English

为什么Python脚本适用于Windows而不适用于Linux?

[英]Why does a Python script work on Windows and not in Linux?

I have from one side Windows 7 with Python 2.7.12 and on the other side Red Hat Enterprise Linux Server release 6.5 with Python 2.6.6. 我从一端使用带有Python 2.7.12的Windows 7,另一端使用带有Python 2.6.6的Red Hat Enterprise Linux Server 6.5版。

I have a script that works fine on Windows but not on RHEL. 我有一个在Windows上运行良好但在RHEL上运行不正常的脚本。

I receive the following syntax error: 我收到以下语法错误:

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

SyntaxError: invalid syntax

It may be caused by different versions of Python on the two systems? 它可能是由两个系统上不同版本的Python引起的?

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

is not supported by Python 2.6. Python 2.6不支持。 In that version you can only open one file in the with statement. 在该版本中,您只能在with语句中打开一个文件。 Instead, you can do 相反,你可以做到

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM