Sqlite and Python — return a dictionary using fetchone()?

后端 未结 8 1705
没有蜡笔的小新
没有蜡笔的小新 2021-01-31 04:03

I\'m using sqlite3 in python 2.5. I\'ve created a table that looks like this:

   create table votes (
      bill text,
      senator_id text,
      vote text)
<         


        
8条回答
  •  [愿得一人]
    2021-01-31 04:05

    I know you're not asking this, but why not just use sqlalchemy to build an orm for the database? then you can do things like,

    
    entry = model.Session.query(model.Votes).first()
    print entry.bill, entry.senator_id, entry.vote
    

    as an added bonus your code will be easily portable to an alternative database, and connections and whatnot will be managed for free.

提交回复
热议问题