python操作sqlite的CRUD實例分析
更新時間:2015年05月08日 10:18:23 作者:work24
這篇文章主要介紹了python操作sqlite的CRUD實現(xiàn)方法,涉及Python操作SQLite數(shù)據(jù)庫CURD相關(guān)技巧,需要的朋友可以參考下
本文實例講述了python操作sqlite的CRUD實現(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]))
希望本文所述對大家的Python程序設(shè)計有所幫助。
您可能感興趣的文章:
- Windows平臺Python連接sqlite3數(shù)據(jù)庫的方法分析
- Python sqlite3事務(wù)處理方法實例分析
- Python簡單操作sqlite3的方法示例
- SQLite3中文編碼 Python的實現(xiàn)
- 詳解Python 數(shù)據(jù)庫 (sqlite3)應(yīng)用
- Python Sqlite3以字典形式返回查詢結(jié)果的實現(xiàn)方法
- Python標準庫之sqlite3使用實例
- Python SQLite3數(shù)據(jù)庫操作類分享
- Python操作sqlite3快速、安全插入數(shù)據(jù)(防注入)的實例
- python操作數(shù)據(jù)庫之sqlite3打開數(shù)據(jù)庫、刪除、修改示例
- Python操作SQLite簡明教程
- Python開發(fā)SQLite3數(shù)據(jù)庫相關(guān)操作詳解【連接,查詢,插入,更新,刪除,關(guān)閉等】
相關(guān)文章
python selenium 獲取接口數(shù)據(jù)的實現(xiàn)
這篇文章主要介紹了python selenium 獲取接口數(shù)據(jù)的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-12-12Python實現(xiàn)同時調(diào)用多個GPT的API
這篇文章主要為大家詳細介紹了Python如何實現(xiàn)同時調(diào)用多個GPT的API,文中的示例代碼簡潔易懂,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2023-09-09python使用seaborn繪圖直方圖displot,密度圖,散點圖
這篇文章主要介紹了python使用seaborn繪圖直方圖displot,密度圖,散點圖,文章圍繞主題展開詳細的內(nèi)容介紹,具有一定的參考價值,需要的小伙伴可以參考一下2022-07-07python 實現(xiàn)二維字典的鍵值合并等函數(shù)
今天小編就為大家分享一篇python 實現(xiàn)二維字典的鍵值合并等函數(shù),具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-12-12PyTorch搭建LSTM實現(xiàn)多變量多步長時序負荷預(yù)測
這篇文章主要為大家介紹了PyTorch搭建LSTM實現(xiàn)多變量多步長時序負荷預(yù)測,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-05-05