title: Syntax error for "with open(file, 'r+'):"
body: <p>I have a bunch of .csh in a directory and I want to open them one by one, search for "//" and replace it with "/" with a python script. How do I do that?</p>
  
  <p>I tried:</p>
  
  <pre><code>import os
  for file in os.listdir("./"):
      if file.endswith(".csh"):
          with open(file, 'r+'):
              data = file.read().replace("//", "/")
              f.write(data)
              f.close()
  </code></pre>
  
  <p>But it gives me:</p>
  
  <pre><code>File "script.py", line 4
      with open(file, 'r+'):
              ^
  SyntaxError: invalid syntax
  </code></pre>