This article through the example code to introduce you to the Python connection SQLite and simple operation, very good, with reference value, need to refer to the friend
Not much nonsense to say, directly to everyone to paste the code, the specific code is as follows:
Import sqlite3# Query def load (table): #连接数据库 con = sqlite3.connect ("e:/datebase/sqlitestudio/park.db") # Get cursor cur = con.cursor () #查询整个表 cur.execute (' select *from ' +table) lists = [' name ', ' password '] if Table = = ' Login ': #将数据库列名存入字典 colnames = {desc[0] for desc in cur.description} stores the dictionary and database data in a list and obtains a record dictionary C11/>rowdicts = [Dict (Zip (lists, row)) for row in Cur.fetchall ()] else: rowdicts = [] for row in cur: Rowdicts.append (Row) con.commit () cur.close () return rowdicts# insert Data def insert_data (Id,name,money): con = sqlite3.connect ("e:/datebase/sqlitestudio/park.db") cur = con.cursor () #使用SQL语句插入 Cur.execute (' INSERT into Charge values (?,?,?) ', (Id,name, Money)) #插入后进行整表查询 to see if Cur.execute was successfully inserted (' SELECT * From Charge ') print (Cur.fetchall ()) con.commit () cur.close ()