gpt4 book ai didi

python - 在Python中从元组格式化为 float ?

转载 作者:太空宇宙 更新时间:2023-11-03 19:24:41 25 4
gpt4 key购买 nike

def tong_thoigian (self,kr,uid,ids,context={}):
obj=self.browse(kr,uid,ids,context=context)[0]
kr.execute('''select name,giolam from x_giolam where name=%s'''%(obj.ma_luong))
kq=kr.fetchall()
tong=0.00000
for i in kq:
tong+=kq[1]
self.write(kr,uid,ids,{'tonggiolam':tong},context=context)

错误是:

TypeError: unsupported operand type(s) for +=: 'float' and 'tuple'

我认为你不关心表和数据库......因为意味着在表x_giolam中获取可能行的函数具有属性giolam和sum它......然后我们就有了员工的工资。

最佳答案

由于查询是“select name,giolam ...”,kq 可能类似于:

[ ('Thong', 324.34), ('Tran', 543.34), ('Thang', 765.52) ... ]

所以我认为你想要:

for record in kq:
tong+=record[1]

而不是tong+=kq[1]

关于python - 在Python中从元组格式化为 float ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8618057/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com