数据库插入
import sqlite3 def CreateDataBase(): try: db =sqlite3.connect("taobao.db") except: print("创建数据库失败") try: db.execute('create table GoodMsg(id varchar(10),price varchar(10),name varchar(40))') except: print("创建表失败或表已经存在") ##将数据写入数据库 def InsertDatabase(data): db =sqlite3.connect("taobao.db") cur = db.cursor() for property in data: try: print("开始插入") sql_insert = ("insert into GoodMsg(id,price,name)values('{0}','{1}','{2}')").format(property[0],property[1],property[2]) cur.execute(sql_insert) db.commit() print("插入成功") except : print('插入失败') ##更新数据库 #def UpdataDataBase(DB): # cur = DB.cursor() # sql_update = '' #def SerchDatabase(): # pass data=[['12','15.3','鞋子'],['13','12','衣服']] #CreateDataBase() InsertDatabase(data)