title: Creating a missing directory / file structure - Python
body: <p>I'm writing a function that does some operations with a <code>.log</code> file: The program checks if <code>/logs/ansible.log</code> exists before proceeding. If <code>/logs/ansible.log</code> doesn't exist, it should go ahead and create the file / directory structure (both don't exist prior).</p>
  
  <pre><code>try:
    if not os.path.exists("/logs/ansible.log"):
       # create the /logs/ansible.log file
  finally:
    # do something
  </code></pre>
  
  <p>I know I can create the <code>ansible.log</code> file with <code>open('ansible.log', 'w')</code> and create the directory with <code>os.makedirs('/logs/')</code>, however how can I simply create <code>'/logs/ansible.log'</code> at once? </p>
  
  <p>*** Assume program is being executed as <code>root</code></p>