Memoize

BasicWerk   EC Support   Technique   Facebook  

20140831191326_Python_sqlite3

Python_sqlite3

 

sample.db
 
% sqlite3 sample.db
SQLite version 3.8.4.3 2014-04-03 16:53:12
Enter ".help" for usage hints.
sqlite> create table sample (id, name, age integer);
sqlite> insert into sample values ("a1", "karry", 34), ("a23", "Sam", 16);
 

 

sqlite3_sample.py
 
#! /usr/bin/env python3.4
# -*- coding: utf-8 -*-
 
import sqlite3
conn = sqlite3.connect('./sample.db')
cur = conn.cursor()
sql = "SELECT id, name, age FROM sample;"
cur.execute(sql)
for id, name, age in cur.fetchall():
    print(id, name, age)
conn.close()
 

 

 
% sqlite3_sample.py
a1 karry 34
a23 Sam 16
 

 


© Shin Nakamura/BasicWerk 2014