1

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.

I have a script that works fine on Windows but not on 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?

1 Answer 1

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

is not supported by Python 2.6. In that version you can only open one file in the with statement. Instead, you can do

with open('pathtofile', 'rb') as f_input:
    with open('pathtofile', 'w') as f_output: 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.