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 6354229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:32:37+00:00 2026-05-24T22:32:37+00:00

Often I select data from a SQLite database into a list of dictionaries using

  • 0

Often I select data from a SQLite database into a list of dictionaries using something like:

conn.row_factory = sqlite3.Row
c = conn.cursor()
selection = c.execute('select * from myTable')
dataset = selection.fetchall()
dataset1 = [dict(row) for row in dataset]

However, given my database background (Foxpro, SQL-server, etc.) I am more used to using table.column format, which I can get using:

dataset2 = [RowObj(row) for row in dataset]  

where

class RowObj(dict):
    def __getattr__(self, name):
        return self[name]

Question – What is preferable for column value addressing, table[‘column’] or table.column? In my opinion the latter looks neater. Is it just a matter of personal preference, or are there pros+cons of each approach?

I also need to bear-in mind that one day the database might be changed from SQLite to something line mySQL, so I want minimum code changes if/when that happens.

I don’t want to use an ORM package like SQLObject or SQLAlchemy at this stage – not until I am convinced they will benefit my applications.

Regards,
Alan

  • 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-24T22:32:38+00:00Added an answer on May 24, 2026 at 10:32 pm

    I fought the row['column'] syntax for a while, but in the end I prefer it. It has two distinct advantages:

    1. row['class'] is correct syntax, but row.class is not; keywords cannot directly be used as property names.
    2. And, more generally, if you ever craft a query whose column names are not valid property names (the above case included) the dictionary-style syntax will allow you to address that column. row.COUNT(*) is obviously not valid syntax, but row['COUNT(*)'] is, etc. (Yes, you could use AS in the query to alias, and that’s fine of course. Still, it’s a valid concern.)

    Having said that, your RowObj class of course supports both means of addressing the columns. I’d still prefer consistency though, and if you have a class column, it’s going to look weird if you address it differently: row.widget, row.dingus, row['class']. (One of these things is not like the other…)

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

Sidebar

Related Questions

I often plug pre-configured lambdas into enumerable methods like 'map', 'select' etc. but the
I'm using C# and SQLite to slice large amounts of data, and I often
Often I use data stemming from a SQL database in R. Typically I do
I often see two styles, INSERT select and insert into select, what are the
I have a Python application. It has an SQLite database, full of data about
My web application parses data from an uploaded file and inserts it into a
My VB.NET application is using importing some excel sheet into access command.CommandText = SELECT
Background: sqlite is great for doing SQL operations on data loaded into databases, but
I often do code review in the following way: Open the SVN log Select
My application has to deal with large amounts of data, usual select size is

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.