python操作sqlite的CRUD实例分析
本文实例讲述了python操作sqlite的CRUD实现方法。分享给大家供大家参考。具体如下:
importsqlite3asdb
conn=db.connect('mytest.db')
cursor=conn.cursor()
cursor.execute("droptableifexistsdatecounts")
cursor.execute("createtabledatecounts(datetext,countint)")
cursor.execute('insertintodatecountsvalues("12/1/2011",35)')
cursor.execute('insertintodatecountsvalues("12/2/2011",42)')
cursor.execute('insertintodatecountsvalues("12/3/2011",38)')
cursor.execute('insertintodatecountsvalues("12/4/2011",41)')
cursor.execute('insertintodatecountsvalues("12/5/2011",40)')
cursor.execute('insertintodatecountsvalues("12/6/2011",28)')
cursor.execute('insertintodatecountsvalues("12/7/2011",45)')
conn.row_factory=db.Row
cursor.execute("select*fromdatecounts")
rows=cursor.fetchall()
forrowinrows:
print("%s%s"%(row[0],row[1]))
cursor.execute("selectavg(count)fromdatecounts")
row=cursor.fetchone()
print("Theaveragecountfortheweekwas%s"%row[0])
cursor.execute("deletefromdatecountswherecount=40")
cursor.execute("select*fromdatecounts")
rows=cursor.fetchall()
forrowinrows:
print("%s%s"%(row[0],row[1]))
希望本文所述对大家的Python程序设计有所帮助。
热门推荐
10 八一幼儿祝福语大全简短
11 公司乔迁食堂祝福语简短
12 婚礼结束聚餐祝福语简短
13 儿媳买车妈妈祝福语简短
14 毕业送礼老师祝福语简短
15 同事辞职正常祝福语简短
16 恭贺新婚文案祝福语简短
17 金店立秋祝福语简短英文
18 婆婆高寿祝福语大全简短