Sie können SQL mit Python verwenden
(Benötigen Sie sqlite3?)
sql.py
# -*- coding: utf-8 -*-
import sqlite3
import sql
connection = sqlite3.connect(':memory:')
bliss = sql.SQL(connection)
bliss.run("CREATE TABLE contributors (firstname VARCHAR, lastname VARCHAR)")
bliss.run("INSERT INTO contributors VALUES (?, ?)", [('Andrew', 'Kuchling'),
('James', 'Henstridge'),
('Daniele', 'Varrazzo'),
('Marc-Andre', 'Lemburg')])
print bliss.one("SELECT firstname FROM contributors WHERE lastname='Lemburg'")
# Marc-Andre
print bliss.all("SELECT firstname FROM contributors")
# [u'Andrew', u'James', u'Daniele', u'Marc-Andre']
print bliss.all("SELECT firstname, LENGTH(lastname) AS length FROM contributors")
'''
[Record(firstname=u'Andrew', length=8),
Record(firstname=u'James', length=10),
Record(firstname=u'Daniele', length=8),
Record(firstname=u'Marc-Andre', length=7)]
'''
Recommended Posts