LoginSignup
9
9

More than 5 years have passed since last update.

pythonのsqlite3モジュールのメモ

Posted at

使う度に調べているので、メモメモ。
Connectionのrow_factoryをRowにセットしておくと、クエリの結果に列名でアクセス出来る。

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"]
9
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
9