title: Python 2.7 Export csv file with data
body: <p>I am trying to export my data into a csv file</p>
  
  <p>My code is as follows</p>
  
  <pre><code>x1=1
  x2=2
  y1=1
  y2=4
  z1=1
  z2=2 
  
  a = (x1,y1,z1)
  b = (x2,y2,z2)
  def distance(x1,y1,z1,x2,y2,z2):
   return (((x2-x1)**2)+((y2-y1)**2)+((z2-z1)**2))**0.5
  w=distance(x1,y1,z1,x2,y2,z2)
  print w
  if w&gt;1 and w&lt;2:
      time = 1
  if w&gt;2 and w&lt;3:
      time = 2
  if w&gt;3 and w&lt;4:
      time = 3
  
  import csv
  
  with open('concert_time.csv', 'w') as output:
  </code></pre>
  
  <p>I am stuck at this last line.  I would like a file with two columns for 'Letter Combinations' and 'Time', and the output to look like:</p>
  
  <pre><code>Letters         Time
  a and b           3
  </code></pre>
  
  <p>I know there is a way to get this output by explicitly labeling a row as '3' for the appropriate time, but I would like a csv file that will change if I change the values of a or b, and thus the value of 'time' would change.  I have tried </p>
  
  <pre><code>writer.writerows(enumerate(range(time), 1))
  </code></pre>
  
  <p>but this does not get me the desired output (in fact it is probably very far off, but I am new to Python so my methods have been guess and check)</p>
  
  <p>Any help is greatly appreciated!</p>