Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python sqlite dict

def dict_factory(cursor, row):
    d = {}
    for idx, col in enumerate(cursor.description):
        d[col[0]] = row[idx]
    return d

conn = sqlite3.connect("data.db")
conn.row_factory = dict_factory
db = conn.cursor()
print(db.execute("SELECT * FROM table"))
>>> [{'col1': 'val1', 'col2': 'val2'}, {'col1': 'val3', 'col2': 'val4'}]
Comment

python sqlite3 dict from query

con.row_factory = sqlite3.Row
Comment

PREVIOUS NEXT
Code Example
Python :: python inf 
Python :: pandas series to numpy array 
Python :: rename index 
Python :: sort the dictionary in python 
Python :: how to create requirements.txt django 
Python :: how to make custom buttons tkinter 
Python :: how to create a role and give it to the author discord.py 
Python :: python weekday 
Python :: how to keep a webdriver tab open 
Python :: python get nearest value in list 
Python :: How can I install XGBoost package in python on Windows 
Python :: python check if string is number reges 
Python :: python async await 
Python :: python remove articles from string regex 
Python :: pandas drop na in column 
Python :: password manager python 
Python :: jupyter lab 
Python :: python regex cheat sheet 
Python :: python code to remove file extension 
Python :: discord py get channel id by name 
Python :: get title attribute beautiful soup 
Python :: clearing canvas tkinter 
Python :: python list comprehension if else 
Python :: How many columns have null values present in them? in pandas 
Python :: python super init 
Python :: flask read form data 
Python :: sum of column in 2d array python 
Python :: numpy matrix 
Python :: how to load keras model from json 
Python :: pygame music player 
ADD CONTENT
Topic
Content
Source link
Name
6+5 =