title: Exporting CSV file from python sqlite3
body: <p>I've been trying to google this for hours now, sorry if the answer is already out there</p>
  
  <p>This is what I have so far:</p>
  
  <pre><code>c.execute("SELECT * FROM table")
  table = c.fetchall()
  print(table)
  
  #to export as csv file
  with open("wub.csv", "wb") as write_file:
       cursor = connection.cursor()
            for row in cursor.execute("SELECT * FROM table"):
            write_file.write(row)
  </code></pre>
  
  <p>But I keep getting an error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "C:/Users/Rachel/Documents/database.py", line 52, in &lt;module&gt;
      write_file.write(row)
  TypeError: a bytes-like object is required, not 'tuple'
  </code></pre>
  
  <p>so I'm pretty sure I'm doing everything wrong -how would I properly export the table to an external CSV file? Thank you</p>
  
  <p>EDIT:
  <a href="http://i.stack.imgur.com/H926m.png" rel="nofollow">to Janekmuric</a></p>