title: Write to CSV from sqlite3 database in python
body: <p>Ok, So I have a database called cars.db which has a table == inventory,</p>
  
  <p>Inventory essentially contains</p>
  
  <pre><code>    ('Ford', 'Hiluz', 2),
      ('Ford', 'Tek', 6),
      ('Ford', 'Outlander', 9),
      ('Honda', 'Dualis', 3),
      ('Honday', 'Elantre', 4)
  </code></pre>
  
  <p>I then wrote this which is meant to edit that to the csv, however, I can't seem to work this out, in some cases I get stuff to print but its not right, and when I try and fix that, nothing prints. Any suggestions to get me on track?</p>
  
  <pre><code>#write table to csv
  
  import sqlite3
  import csv
  
  with sqlite3.connect("cars.db") as connection:
      csvWriter = csv.writer(open("output.csv", "w"))
      c = connection.cursor()
  
      rows = c.fetchall()
  
      for x in rows:
          csvWriter.writerows(x)
  </code></pre>