I have the following file:
import sys
lines = []
with open(sys.argv[1]) as f: #this works fine
for line in f:
lines.append(line.replace('\\', '/')
with open(sys.argv[1], 'w') as f: #this gives a syntax error
for line in lines:
f.write(line)
Whenever I try to run it, I get a syntax error on the with part of the second with statement:
File "ChangeSlashes.py", line 7
with open(sys.argv[1], 'w') as f:
^
SyntaxError: invalid syntax
Why is this happening, and why is it only when I specify the mode in open()?
lines.append(line.replace('\\', '/')didnt close parens on previous line.