title: How can I edit a plain text file in Python?
body: <p>I've been trying to create a python script that edits a file, but if the file is not already there, it has an error like this:</p>
  
  <pre><code>    Traceback (most recent call last):
          File "openorcreatfile.py", line 56, in &lt;module&gt;
          fileHandle = (pathToFile, 'w')
          IOError: [Errno 2] No such file or directory: '/home/me/The_File.txt'
  </code></pre>
  
  <p>It works fine if the file exists. I've also tried this:</p>
  
  <pre><code>    fileHandle = (pathToFile, 'w+')
  </code></pre>
  
  <p>But it comes up with the same error. Do I need to explicitly check if the file is there? If so, how do I create the file?</p>
  
  <p>EDIT: Sorry, I realized the folder was missing. I'm an idiot.</p>