title: Python and csv.writer: Open in every loop or keep open?
body: <p>In my little python script I open a csv file, write a header to it, process a loop in which I open many other csv files to look in them and finally I write once per loop into the first csv:</p>
  
  <pre><code>import csv
  
  with open(output_file, 'wb') as f:
      outfileWriter = csv.writer(f, delimiter=',')
      # write header
  
  for loop_file in a_list_of_files:
      with open(loop_file) as s:
          # calculate something on the file and write one line to f
  </code></pre>
  
  <p>Now is it better to keep f open (that is, indent the loop), or open it once peer loop? What's more pythonic/faster?</p>