格式从元组到浮在python?

时间:2011-12-23 16:00:47

标签: python

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'

我认为你不关心表和数据库......因为表{@ 1}}中获取mayny行的函数具有属性x_giolam并将其求和...然后我们有工作人员的薪水。

1 个答案:

答案 0 :(得分:1)

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

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

所以我想你想要:

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

而不是tong+=kq[1]