title: Write file to a directory that doesn't exist
body: <p>How do I using <code>with open() as f: ...</code> to write the file in a directory that doesn't exist.</p>
  
  <p>For example:</p>
  
  
  
  <pre class="lang-py prettyprint-override"><code>with open('/Users/bill/output/output-text.txt', 'w') as file_to_write:
      file_to_write.write("{}\n".format(result))
  </code></pre>
  
  <p>Let's say the <code>/Users/bill/output/</code> directory doesn't exist.  If the directory doesn't exist just create the directory and write the file there.</p>