title: Python csv writer "AttributeError: __exit__" issue
body: <p>I have three variables I want to write in a tab delimited .csv, appending values each time the script iterates over a key value from the dictionary. </p>
  
  <p>Currently the script calls a command, regex the stdout as <code>out</code> then assigns the three defined regex groups to individual variables for writing to .csv labeled <code>first</code> <code>second</code> and <code>third</code>. I get a __exit_ error when I run the below script.</p>
  
  <p>/note I've read up on csv.writer and I'm still confused as to whether I can actually write multiple variables to a row.</p>
  
  <p>Thanks for any help you can provide.</p>
  
  <pre><code> import csv, re, subprocess
  
   for k in myDict:
       run_command = "".join(["./aCommand", " -r data -p ", str(k)])
       process = subprocess.Popen(run_command,
                                  shell=True,
                                  stdout=subprocess.PIPE,
                                  stderr=subprocess.PIPE)
       out, err = process.communicate()
       errcode = process.returncode
       pattern = re.compile('lastwrite|(\d{2}:\d{2}:\d{2})|alert|trust|Value')
       grouping = re.compile('(?P&lt;first&gt;.+?)(\n)(?P&lt;second&gt;.+?)([\n]{2})(?P&lt;rest&gt;.+[\n])', 
                             re.MULTILINE | re.DOTALL)
  
  
      if pattern.findall(out):         
          match = re.search(grouping, out)
          first = match.group('first')
          second = match.group('second')
          rest = match.group('rest')
  
       with csv.writer(open(FILE, 'a')) as f:
          writer = csv.writer(f, delimiter='\t')
          writer.writerow(first, second, rest)
  </code></pre>
  
  <p>Edit: Requested in the comments to post entire traceback, note the line listed in traceback will not match the above code as this is not the entire script. </p>
  
  <pre><code>Traceback (most recent call last):
  File "/mydir/pyrr.py", line 60, in &lt;module&gt;
  run_rip()
  File "/mydir/pyrr.py", line 55, in run_rip
  with csv.writer(open('/mydir/ntuser.csv', 'a')) as f:
  AttributeError: __exit__
  </code></pre>
  
  <p>Answer: Using the below comment I was able to write it as follows.</p>
  
  <pre><code>f = csv.writer(open('/mydir/ntuser.csv', 'a'),
                         dialect=csv.excel,
                         delimiter='\t')
  f.writerow((first, second, rest))
  </code></pre>