title: Python: with open(filename, 'w') for a file that does not exist
body: <h1>Background</h1>
  
  <p>I'm trying to write a script that creates a new LaTeX-file from a template I've made and
  I've run into a bit of a snag when it comes to using the following code:</p>
  
  <pre><code>with open(filename + '.tex', 'w'):
      # Do stuff to filename.tex
      ...
  </code></pre>
  
  <p>Consider the above as <strong>Option A</strong>.</p>
  
  <p>Here <code>filename.tex</code>, <code>filename</code> is a variable, (probably) doesn't exist within the directory from which the script is executed by the user. In <strong>Option A</strong> the file isn't created
  by the <code>with open(...)</code> statement. I obviously need to create <code>filename.tex</code> in this context.</p>
  
  <p>There is another way to open files, which is to be considered as <strong>Option B</strong>:</p>
  
  <pre><code>f = open(filename.tex, 'w+')
  </code></pre>
  
  <p>In the above statement the file is created if it does not exist.</p>
  
  <p>Hence, my question:<br>
  Which of these options should I use if I mean to write
  clear, well written code, that adheres to the shared view
  of the Python community? <em>(Pythonic)</em></p>
  
  <p>If <strong>Option A</strong>,<br>
  I'd appreciate directions as to how to <code>touch</code> the file if it does not
  already exist, a link would be splendid. (Or include in the answer)</p>