python操作sqlite的CRUD實(shí)例分析
本文實(shí)例講述了python操作sqlite的CRUD實(shí)現(xiàn)方法。分享給大家供大家參考。具體如下:
import sqlite3 as db
conn = db.connect('mytest.db')
cursor = conn.cursor()
cursor.execute("drop table if exists datecounts")
cursor.execute("create table datecounts(date text, count int)")
cursor.execute('insert into datecounts values("12/1/2011",35)')
cursor.execute('insert into datecounts values("12/2/2011",42)')
cursor.execute('insert into datecounts values("12/3/2011",38)')
cursor.execute('insert into datecounts values("12/4/2011",41)')
cursor.execute('insert into datecounts values("12/5/2011",40)')
cursor.execute('insert into datecounts values("12/6/2011",28)')
cursor.execute('insert into datecounts values("12/7/2011",45)')
conn.row_factory = db.Row
cursor.execute("select * from datecounts")
rows = cursor.fetchall()
for row in rows:
print("%s %s" % (row[0], row[1]))
cursor.execute("select avg(count) from datecounts")
row = cursor.fetchone()
print("The average count for the week was %s" % row[0])
cursor.execute("delete from datecounts where count = 40")
cursor.execute("select * from datecounts")
rows = cursor.fetchall()
for row in rows:
print("%s %s" % (row[0], row[1]))
希望本文所述對(duì)大家的Python程序設(shè)計(jì)有所幫助。
- Windows平臺(tái)Python連接sqlite3數(shù)據(jù)庫(kù)的方法分析
- Python sqlite3事務(wù)處理方法實(shí)例分析
- Python簡(jiǎn)單操作sqlite3的方法示例
- SQLite3中文編碼 Python的實(shí)現(xiàn)
- 詳解Python 數(shù)據(jù)庫(kù) (sqlite3)應(yīng)用
- Python Sqlite3以字典形式返回查詢結(jié)果的實(shí)現(xiàn)方法
- Python標(biāo)準(zhǔn)庫(kù)之sqlite3使用實(shí)例
- Python SQLite3數(shù)據(jù)庫(kù)操作類分享
- Python操作sqlite3快速、安全插入數(shù)據(jù)(防注入)的實(shí)例
- python操作數(shù)據(jù)庫(kù)之sqlite3打開(kāi)數(shù)據(jù)庫(kù)、刪除、修改示例
- Python操作SQLite簡(jiǎn)明教程
- Python開(kāi)發(fā)SQLite3數(shù)據(jù)庫(kù)相關(guān)操作詳解【連接,查詢,插入,更新,刪除,關(guān)閉等】
相關(guān)文章
python 判斷參數(shù)為Nonetype類型或空的實(shí)例
今天小編就為大家分享一篇python 判斷參數(shù)為Nonetype類型或空的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-10-10
Django中celery執(zhí)行任務(wù)結(jié)果的保存方法
今天小編就為大家分享一篇Django中celery執(zhí)行任務(wù)結(jié)果的保存方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-07-07
Python借助with語(yǔ)句實(shí)現(xiàn)代碼段只執(zhí)行有限次
這篇文章主要介紹了Python借助with語(yǔ)句實(shí)現(xiàn)代碼段只執(zhí)行有限次,首先要定義一個(gè)能夠在with語(yǔ)句中使用的類實(shí)現(xiàn)enter和exit,下文詳細(xì)介紹需要的小伙伴可以參考一下2022-03-03
Python根據(jù)成績(jī)分析系統(tǒng)淺析
在本篇文章里小編給大家分享了關(guān)于Python根據(jù)成績(jī)分析是否繼續(xù)深造一個(gè)系統(tǒng)的相關(guān)知識(shí)點(diǎn),有需要的朋友們學(xué)習(xí)下。2019-02-02
python中前綴運(yùn)算符 *和 **的用法示例詳解
這篇文章主要介紹了python中前綴運(yùn)算符 *和 **的用法,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2020-05-05
Python多進(jìn)程方式抓取基金網(wǎng)站內(nèi)容的方法分析
這篇文章主要介紹了Python多進(jìn)程方式抓取基金網(wǎng)站內(nèi)容的方法,結(jié)合實(shí)例形式分析了Python多進(jìn)程抓取網(wǎng)站內(nèi)容相關(guān)實(shí)現(xiàn)技巧與操作注意事項(xiàng),需要的朋友可以參考下2019-06-06
python去除刪除數(shù)據(jù)中\(zhòng)u0000\u0001等unicode字符串的代碼
這篇文章主要介紹了python去除刪除數(shù)據(jù)中\(zhòng)u0000\u0001等unicode字符串的代碼,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-03-03
Python中導(dǎo)入自定義模塊的幾種方法總結(jié)
這篇文章主要介紹了Python中導(dǎo)入自定義模塊的幾種方法總結(jié),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-01-01

