Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1099577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:45:18+00:00 2026-05-17T00:45:18+00:00

I have a Sqlite 3 and/or MySQL table named clients.. Using python 2.6, How

  • 0

I have a Sqlite 3 and/or MySQL table named “clients”..

Using python 2.6, How do I create a csv file named Clients100914.csv with headers?
excel dialect…

The Sql execute: select * only gives table data, but I would like complete table with headers.

How do I create a record set to get table headers. The table headers should come directly from sql not written in python.

w = csv.writer(open(Fn,'wb'),dialect='excel')
#w.writelines("header_row")
#Fetch into sqld
w.writerows(sqld)

This code leaves me with file open and no headers. Also cant get figure out how to use file as log.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T00:45:19+00:00Added an answer on May 17, 2026 at 12:45 am
    import csv
    import sqlite3
    
    from glob import glob; from os.path import expanduser
    conn = sqlite3.connect( # open "places.sqlite" from one of the Firefox profiles
        glob(expanduser('~/.mozilla/firefox/*/places.sqlite'))[0]
    )
    cursor = conn.cursor()
    cursor.execute("select * from moz_places;")
    with open("out.csv", "w", newline='') as csv_file:  # Python 3 version    
    #with open("out.csv", "wb") as csv_file:              # Python 2 version
        csv_writer = csv.writer(csv_file)
        csv_writer.writerow([i[0] for i in cursor.description]) # write headers
        csv_writer.writerows(cursor)
    

    PEP 249 (DB API 2.0) has more information about cursor.description.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an SQLite database, eventually will be a MySQL database and I'm using
I have two SQLite (also MySQL could be fine) databases with same table structures
I have the following named_scope which works fine in MySQL and sqlite but bombs
I have a sqlite table representing a weighted directed graph. The columns are as
I have a SQLite table called posts . An example is shown below. I
Given that I have a table with a column of TEXT in it (MySQL
I'm converting a sqlite3 database to mysql. I have a nice command file for
I have an export SQL file containing tables and data from MySQL and I
I started developing my rails application using sqlite. I have reached a point where
working with sqlite3 for local dev. Prod DB is MySql. Have a migration file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.