title: ValueError: must have exactly one of create/read/write/append mode
body: <p>I have a file that I open and i want to search through till I find a specific text phrase at the beginning of a line. I then want to overwrite that line with 'sentence'</p>
  
  <pre><code>sentence = "new text"           "
  with open(main_path,'rw') as file: # Use file to refer to the file object
      for line in file.readlines():
          if line.startswith('text to replace'):
              file.write(sentence)
  </code></pre>
  
  <p>I'm getting:</p>
  
  <pre><code>Traceback (most recent call last):
   File "setup_main.py", line 37, in &lt;module&gt;
  with open(main_path,'rw') as file: # Use file to refer to the file object
  ValueError: must have exactly one of create/read/write/append mode
  </code></pre>
  
  <p>How can I get this working?</p>