title: PYTHON 3.7 - export the result of a query DB to a CSV file
body: <p>I recently started using python, and I'm trying to export the result of a query to a csv file, but without success. </p>
  
  <pre><code>id = 563;
  
  try:
      cursor.execute("SELECT start_time,end_time FROM appointment WHERE box_id=%s", (id,))
      data = cursor.fetchall()
  
      with open('dataTester.csv', 'w') as fp:
          a= csv.writer(fp, delimiter=',')
          for line in data:
             a.writerows(line)
  
      for row in data:
          print (row[0],row[1])
      cursor.close()
      connection.close()
  except:
      print ("error")
  
  connection.close()
  </code></pre>
  
  <p>I have the following error:</p>
  
  <p>iterable expected, not datetime.datetime</p>
  
  <p>the error is at the line: <code>a.writerows(line)</code></p>