python - python sqlite插入错误
问题描述
我正在使用 python 3 tkinter 和 sqlite 我在 tkinter 中有数据Text Widget
,然后我需要将其拆分并保存在数据库表中这是我的代码尝试
data = txtReceipt.get("4.0" ,"end")
for line in data.splitlines()[2:-2]:
no = line.split()[2:3]
name = line.split()[1:2]
price = line.split()[3:4]
series = line.split()[:1]
print(no)
c.execute("INSERT INTO billed_items(item_name,billed_qty,price,item_bill_series) VALUES(?,?,?,?)",(name),(no),(price),(series))
conn.commit()
TypeError: function takes at most 2 arguments (5 given)
但是当我尝试读回文本小部件时,我也收到此错误消息任何帮助
su=c.execute("SELECT * FROM billed_items")
for row in su:
text = str(row)
txtReceipt.insert("end",str(row[0])+" "+str(row[1])+'\t\t'+str(row[2])+'\t'+" "+str(row[3])+"\n")
在那里它只读取表中的最后一行我不知道为什么他不能读取所有行
解决方案
这些值需要在元组中提供。尝试这个
query = ("INSERT INTO billed_items(item_name,billed_qty,price,item_bill_series) VALUES(?,?,?,?)")
c.execute(query,((name),(no),(price),(series))
conn.commit()
推荐阅读
- python - 在嵌套函数中访问python全局变量
- spring-boot - 将命令行参数传递给 AWS Fargate 容器
- python - 为什么我的 threading.Event() 会减慢线程速度?
- ubuntu - Ubuntu证书问题
- c - 为什么 mktime 少给我一个小时?
- ios - 检查开发证书。以编程方式到期
- elixir - 在 Elixir Phoenix 中指定需要经过身份验证的用户的资源路由
- unity3d - 我正在尝试使用一些统一类来学习 c#,但我遇到了一些问题
- python - TensorFlow 强化学习 softmax 层
- python - Python,具有异常值的 Lomax 分布后的随机数生成