import sqlite3 dbpath = 'C:\Django\workplace\sf\d1.sqlite3' conn = sqlite3.connect(dbpath) cu = conn.cursor() #Update row. cu.execute('update sinfors_hvsrvs set freedisk="1000" where serverip="10.160.26.30"') conn.commit() #Select datas. cu.execute('select * from sinfors_hvsrvs') print cu.fetchall()
import sqlite3,os,csv dbpath = 'C:\Django\workplace\sf\d1.sqlite3' conn = sqlite3.connect(dbpath) cu = conn.cursor() sql_insert = '''insert into sinfors_hvsrvs values (?,?,?,?,?)''' datas=[(1,'a','b'),(2,'aa','bb')] #循环插入多条数据 cu.execute('delete from sinfors_hvsrvs') conn.commit() for data in datas: cu.execute(sql_insert,data) conn.commit() # cu.execute('select * from sinfors_hvsrvs') # print cu.fetchall() cu.close()
http://www.cnblogs.com/hongten/p/hongten_python_sqlite3.html