Python簡單操作sqlite3的方法示例
本文實(shí)例講述了Python簡單操作sqlite3的方法。分享給大家供大家參考,具體如下:
import sqlite3 def Test1(): #con =sqlite3.connect("D:\\test.db") con =sqlite3.connect(":memory:") #store in memory cur =con.cursor() try: cur.execute('create table score(id integer primary key,name varchar(10),scores integer)') cur.execute("insert into score values(0,'Rose',87)") cur.execute("insert into score values(1,'Alice',78)") cur.execute("insert into score values(2,'Helon',100)") cur.execute("insert into score values(3,'Tom',98)") cur.execute("insert into score values(4,'jack',198)") cur.execute("insert into score values(5,'Tony',198)") cur.execute("insert into score values(6,'David',99)") cur.execute("update score set scores =? where id=?",(45,3)) cur.execute("update score set name=? where id=?",("John",0)) cur.execute("delete from score where id =1") except Exception,e: print "There are some except",e con.commit() print "Insert Complete" print "-----------------------------------------" print "Last row id is ",cur.lastrowid cur.execute('select * from score') print cur.fetchall() print "----------------------------------------" cur.execute("select count(*) from score") print "Current Rows is :",cur.fetchall()[0] cur.close() con.close() if __name__ =='__main__': Test1() print "hello world"
更多關(guān)于Python相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Python常見數(shù)據(jù)庫操作技巧匯總》、《Python編碼操作技巧總結(jié)》、《Python圖片操作技巧總結(jié)》、《Python數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Python Socket編程技巧總結(jié)》、《Python函數(shù)使用技巧總結(jié)》、《Python字符串操作技巧匯總》、《Python入門與進(jìn)階經(jīng)典教程》及《Python文件與目錄操作技巧匯總》
希望本文所述對大家Python程序設(shè)計(jì)有所幫助。
相關(guān)文章
Python 讀取 YUV(NV12) 視頻文件實(shí)例
今天小編就為大家分享一篇Python 讀取 YUV(NV12) 視頻文件實(shí)例,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-12-12Python求均值,方差,標(biāo)準(zhǔn)差的實(shí)例
今天小編就為大家分享一篇Python求均值,方差,標(biāo)準(zhǔn)差的實(shí)例,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-06-06Pyinstaller打包.py生成.exe的方法和報(bào)錯總結(jié)
今天小編就為大家分享一篇關(guān)于Pyinstaller打包.py生成.exe的方法和報(bào)錯總結(jié),小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧2019-04-04Python調(diào)用C++,通過Pybind11制作Python接口
今天小編就為大家分享一篇關(guān)于Python調(diào)用C++,通過Pybind11制作Python接口,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧2018-10-10教你用Python實(shí)現(xiàn)一個輪盤抽獎小游戲
Python提供了許多個圖像開發(fā)界面的庫,比如現(xiàn)在主流的Tkinter,wxPython,pyqt5等,三種各有優(yōu)點(diǎn),也各有缺點(diǎn),下面對其分別進(jìn)行介紹和對比,并編寫代碼實(shí)現(xiàn)一個輪盤轉(zhuǎn)盤抽獎小游戲.需要的朋友可以參考下2021-05-05Keras load_model 導(dǎo)入錯誤的解決方式
這篇文章主要介紹了Keras load_model 導(dǎo)入錯誤的解決方式,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-06-06