title: Python3.4: Opening file with mode 'w' still gives me FileNotFound error
body: <p>I'm having a small problem: while using the function <code>open()</code> with the <code>'w'</code> mode, all documentation says that the file is created if it does not exist. Unfortunately, it appears that in my case, I get a <code>FileNotFound</code> error for some reason. </p>
  
  <pre><code>with open(newFileName, 'w') as newFile:
      #CODE
  </code></pre>
  
  <p>I receive the following error:</p>
  
  <pre><code>FileNotFoundError: [Errno 2] No such file or directory: 'path of file I have specified'
  </code></pre>
  
  <p>Any idea of why this might be? Thanks in advance! </p>
  
  <p>EDIT: For those asking if the directory exists or not, I have made small changes to the code that might show you it is indeed the good path.</p>
  
  <pre><code>if not os.path.exists("example"):
      os.makedirs("example")
  
  BASE_DIR = os.path.dirname(os.path.abspath(__file__))
  
  newFileName = "example/restOfPath"
  newFileName = os.path.join(BASE_DIR,newFileName)
  
  with open(newFileName, 'w') as newFile:
  </code></pre>
  
  <p>I still get the following error:</p>
  
  <pre><code>FileNotFoundError: [Errno 2] No such file or directory: 'correctPathToDirectory/example/restOfPath'
  </code></pre>
  
  <p>EDIT2: Disregard this question, problem solved. A second directory was being created after "example", thus it not working. Silly error.</p>