Notes on python's sqlite3 module

I check it every time I use it, so it's a memo memo. If you set row_factory of Connection to Row, you can access the result of query by column name.

sqlite.py


#!/usr/bin/env python




import sqlite3




con = sqlite3.connect(":memory:")
con.executescript("""
create table temp (hoge text);
insert into temp values ('piyo');
insert into temp values ('fuga');
""")
con.commit()




con.row_factory = sqlite3.Row
cur = con.execute("""
select * from temp
""")




for c in cur:
    print c["hoge"]

Recommended Posts

Notes on python's sqlite3 module
Notes on Flask
Notes on neural networks
Celery notes on Django
Notes on installing PycURL
Notes on using Alembic
Notes on SciPy.linalg functions
Notes on tf.function and Tracing
Notes on installing dlib on mac
Notes on * args and ** kargs
Notes on defining PySide slots (2)
[Django] Notes on using django-debug-toolbar
Where I stumbled on SQLite3
Install module on Anaconda (Mac)
Notes on pyenv and Atom
Notes on defining PySide slots
[Python] Notes on data analysis
Notes on optimization using Pytorch
Notes on installing Python on Mac
Notes on studying multidimensional scaling
Notes on installing pipenv on Mac
Notes on installing Anaconda 3 on Windows
Notes on imshow () in OpenCV
Notes on installing Python on CentOS
Notes on Python and dictionary types
Notes on package management with conda
Notes on using MeCab from Python
[Golang] Notes on frequently used functions
Notes on how to use pywinauto
How to use Python's logging module
Notes on using post-receive and post-merge
Notes on how to use featuretools
Sort names with Python's random module
Notes on installing Python using PyEnv
Notes on using rstrip with python.
Notes on accessing dashDB from python
Learn about logging using Python's logging module ①
Notes on how to use doctest
Error compiling mmh3 module on CircleCI
Notes on using matplotlib on the server
Notes on how to write requirements.txt
Notes on installing Ubuntu 18.04 on the XPS 15 7590
(Beginner) Notes on using pyenv on Mac