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

  • Home
  • SEARCH
  • 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 3350900
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:50:36+00:00 2026-05-18T01:50:36+00:00

When I do someting like sqlite.cursor.execute(SELECT * FROM foo) result = sqlite.cursor.fetchone() I think

  • 0

When I do someting like

sqlite.cursor.execute("SELECT * FROM foo")
result = sqlite.cursor.fetchone()

I think have to remember the order the columns appear to be able to fetch them out, eg

result[0] is id
result[1] is first_name

is there a way to return a dictionary? so I can instead just use result[‘id’] or similar?

The problem with the numbered columns is, if you write your code then insert a column you might have to change the code eg result[1] for first_name might now be a date_joined so would have to update all the code…

  • 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-18T01:50:36+00:00Added an answer on May 18, 2026 at 1:50 am

    David Beazley has a nice example of this in his Python Essential Reference.
    I don’t have the book at hand, but I think his example is something like this:

    def dict_gen(curs):
        ''' From Python Essential Reference by David Beazley
        '''
        import itertools
        field_names = [d[0].lower() for d in curs.description]
        while True:
            rows = curs.fetchmany()
            if not rows: return
            for row in rows:
                yield dict(itertools.izip(field_names, row))
    

    Sample usage:

    >>> import sqlite3
    >>> conn = sqlite3.connect(':memory:')
    >>> c = conn.cursor()
    >>> c.execute('create table test (col1,col2)')
    <sqlite3.Cursor object at 0x011A96A0>
    >>> c.execute("insert into test values (1,'foo')")
    <sqlite3.Cursor object at 0x011A96A0>
    >>> c.execute("insert into test values (2,'bar')")
    <sqlite3.Cursor object at 0x011A96A0>
    # `dict_gen` function code here
    >>> [r for r in dict_gen(c.execute('select * from test'))]
    [{'col2': u'foo', 'col1': 1}, {'col2': u'bar', 'col1': 2}]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My current query looks something like this: SELECT SUBSTR(name,1,1), COUNT(*) FROM files GROUP BY
I have about 20,000 records (coming from an SQLite db) that I need to
I had someting like this in my code (.Net 2.0, MS SQL) SqlConnection connection
Does something like this affect performance badly? var myQuery = from c in Customers
from this post sqlite python insert I learned inserting into tables but now I
I am writing a app in python and utilzing sqlite. I have a list
Here is the table in which I am retrieving the data from an SQLite
I have a script that parses xml file to generate SQLite table automatically. And,
Something like var life= { users : { guys : function(){ this.SOMETHING.mameAndDestroy(this.girls); }, girls
Something like this might had worked <%= Html.RouteLink(, new { controller = Article, action

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.